C++ :: Chat Messenger - Running Multiple Threads At Same Time

Sep 18, 2013

I'm doing work on chat messenger and facing difficulty to run multiple threads at the same time. Here is the sample code.

void menu();
void groupChat();
void personalChat();
int main() {
sf::Thread thread(&menu());
thread.launch();

[Code] ....

In my program, after menu when he selects a choice, next display of menu wait the termination of the selected thread.
while i want to show menu right after when a menu is selected.

View 2 Replies


ADVERTISEMENT

C++ :: Accessing And Working With Vector From Multiple Threads

Oct 20, 2014

I have a vector that I would like to access and work with from multiple threads. I have created an example below to illustrate the functionality that I would like to accomplish.

The goals are to be (1) high speed, (2) thread safe, and (3) *if possible* continue to use vectors as my larger project uses vectors all over the place and as such I would like to maintain that.

However, if I need to switch from vectors to something else then I am open to that as well.

The following example below compiles but crashes rather quickly because it is not thread safe.

How I can fix the example below which I can then apply to my larger project?

#include <string>
#include <vector>
#include <ctime>
#include <thread>
#include <iostream>
#include <random>
#include <atomic>
#include <algorithm>
enum EmployeeType {

[Code] ....

View 1 Replies View Related

C++ :: Reading / Writing File On Multiple Threads?

Aug 7, 2013

I'm currently working on a server for handling clients in a 2d online game and I wrote some regular fstream file code for handling the file that stores their information and I was about to implement it into the server, then I realized there might be a problem having it open multiple times concurrently, so I googled it and came up with
posts like

[URL]

I'm wondering if I can just treat it like everything else or will I have to do something specific for opening on multiple threads?

p.s. I did read those posts but I'm very new to multithreading

View 16 Replies View Related

C# :: Running A Class At Design Time

Aug 7, 2014

I have a Class called 'DataManager' which contains a list of my 'DataItem' objects (this are created by an XML file).

I have also created some custom controls which, among other things, has a property to link it to a "DataItem" object.

My question is, is it possible to create an instance of my DataManager class at design time (which runs all the code as it would at run time to create all the DataItems from the XML)?

I want to do this so that I can update my DataItem property in my custom controls to use a UITypeEditor which then allows me to link to a DataItem at design time.

View 4 Replies View Related

C++ :: Running A Procedure Repeatedly After A Set Time Interval

May 28, 2013

I have a certain piece of code that I want to run every 2 minutes. One of my ideas is to get the time and modules that with whatever number represents 2 minutes. Would this work?

View 4 Replies View Related

C++ :: Identify End Of Function Code At Running Time

Apr 16, 2013

I want to implement some "debugger like" tool (very limited one, just identify at running time the current stack trace, and print messages from the user) on some code that the user wrote. what I get from the user is a function name (in the beginning of it's declaration), and when the user want to print some message he uses some print macro I should implement.

My target is printing the stack call, and all the messages that the user wrote, in the right place on the running place.

By what c++ feature can know on running time that a specific function code has ended??

Its easy to push a function to some vector when it called (since I get its name from the user), but when it ends and return to the function called it...

View 14 Replies View Related

C/C++ :: Running Multiple Terminal In Xcode

Oct 5, 2014

I am using Xcode to do c++ programming and I have a c++ code, with different input arguments. I want to achieve that in Xcode, I could run multiple simultaneous running of my c++ code. However, the current problem is that once one code finishes, its terminal window automatically closed and I do not have time to look at its result. Thus computer time is wasted. Is there a way to run multiple same c++ code with different arguments input?

View 6 Replies View Related

C++ :: Running Same Code With Different Inputs On Multiple CPUs

May 28, 2014

I have a C++ code reading large data from an input txt file, doing some calculation on the data, and writing the result of calculation in another txt file.

I have about 300 input files, and the calculation time for each input file is pretty long (~4 days on a single CPU), so I would like to run the same code on multiple CPUs for different inputs.

Which is the most appropriate strategy in this case, multithreading, mpi or something else?

View 4 Replies View Related

C++ :: Measure Sorting Algorithm For Performance In Terms Of Number Of Steps And CPU Running Time

May 13, 2014

I have an school assignment that asks me to measure the most famous sorting algorithms for performance in terms of number of steps and CPU running time. ( Here I'm testing for running time)

I decided to test for bubble sort first:

#include <iostream>
#include <ctime>
using namespace std;
void bubbleSort(int ar[], int size) {
int temp;

[Code] ....

So basically what I want to know is:

1. Is this clock function giving the correct CPU running time?

2. Is there any way to write code that would measure the number of steps for each algorithm?

3.I need to test it for number of integers=100 then 200, then 300... Well you get my point, and I don't want to have to actually input 200 numbers with my keyboard. Is there any way to generate as many entries as I want?

View 4 Replies View Related

C# :: Send Multiple Files Over Tcp At The Same Time In C Sharp?

Nov 29, 2010

I have a tcp client - server implementation running in the same program, on different background worker threads. There will be instances of this program on multiple computers so they can send and receive files between each other. I can send files sequentially between computers using network stream, but how would I send multiple files at the same time from computer A to B.

Sending multiple files over one connection ( socket ) is fine, but having multiple network streams sending data to a client, the client doesn't know which chunk of data is apart of which file ?

View 3 Replies View Related

C :: Linux Socket Multiple Connections But With Different Time Rate

Feb 6, 2015

i want to write a server and a client as below:

The server(and not the clients) will connect to the clients and just send a message. The idea is to be able to connect at each client a different time.

e.g
every 10mins connect at client 1
every 2mins connect at client 2
every 1hour connect at client 3
and so on...

So how to implement this ? Should i create a new child process for each connection and what about the timing ? A pseudo code also will work.

View 4 Replies View Related

C :: Using Select Function In Multiuser Chat Over TCP/IP

Jun 2, 2014

I am trying to write a program for a multiuser chat. I am trying to use select() function but I still cannot use the server for multiusers. I am able to access only one client at a time. I am running the code in Windows 7 using Visual Studio's Command Prompt. Here is the server code.

Code:
#include <stdio.h>
#include <winsock.h>
#include <stdlib.h>
#define WSVERS MAKEWORD(2,0)
WSADATA wsadata;
int main(int argc, char *argv[]) {

[Code] .....

View 3 Replies View Related

C :: Simple Way To Have Instant Communication In TCP/IP Chat Program?

Mar 25, 2014

My program allows a server and a client to chat over a socket. Currently I have to wait for one of them to type a message and press enter, before a message from the other person can be received.

Is there a simple way for messages to be received instantly - but not disturb any message that is being typed in?

View 2 Replies View Related

C :: Multi User Chat Over TCP/IP In Visual Studio

Jun 1, 2014

I want to have a multi user chat over TCP/IP. I already have the code for both the server and the client and so far I am able to send messages from the client to the server. Now I want to make it a multi user chat. I am executing the codes using Visual studio's Command prompt(not Windows Command Prompt). I have read somewhere that we have to use select() function.

View 2 Replies View Related

C :: Use SIGNALS To Control Threads

Nov 11, 2013

I've to use SIGNALS to control threads. Here's my code without the use of signals as I'm no good at that

Code:

#include <pthread.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
}

[code]....

View 4 Replies View Related

C++ ::  threads To Take Sequential Turns

Jun 30, 2014

#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>

int turn = 1;
int counter = 0;
int t, n;

[Code] ....

I found this program in a forum and it creates 1 to t threads with each thread pointing to the next and the last thread pointing to the first thread and it allows each thread to sequentially take a turn until all threads have taken n turns. That is when the program ends.

My doubt is if we see in void *tFunc(void *arg) function, first thread locks the mutex and then wait there forever till it's turn comes.Lets say if I spwan 1000 threads and they have take 10 turns each sequentially and what if a 550th thread locks the mutex as soon as the program starts and waiting for its turn which will never happen because still (turn=1) which means it's first thread's turn and first 549 threads have to complete their 1st turn before this 550 threda's turn comes.Doesnt this result in deadlock?

View 2 Replies View Related

C++ :: Encapsulate Two Threads In A Class?

Apr 29, 2014

how to encapsulate two threads in a class?

View 1 Replies View Related

C++ :: Stopping Threads Without Using Local Var?

Aug 31, 2014

Here's my code,

#include <iostream>
#include <unistd.h>
#include <thread>
using namespace std;
void Blink();

[Code] .....

The problem is i don't want to use local vars , is ther anyway do end the loop safely(removing all the vars used in function and etc) without using a local var ?

View 3 Replies View Related

C/C++ :: Suspending And Resuming Threads

Apr 18, 2014

#include <stdio.h>
#include <pthread.h>
int i; // loop control variable
int *id; // array used to pass parameter of id
int nThreads; // #threads

[Code]....

I want to know where I am going wrong. I am strong in java but not in c so that may be my problem.

View 9 Replies View Related

C++ :: Creating And Terminating Threads?

Aug 31, 2014

I had a requirement where i needed to create a thread and if the execution of thread is not completed in 5 minutes i needed to terminate its execution and continue with other part of the code.

I used the below code to create the thread

_beginthread(FuncnCall,0,NULL);

HANDLE hThread = GetCurrentThread();

Then after this code, I used the below code to check for 5 minutes

for (int i=1;i<=0;i++) {
printf("Value of i=%d
",i);
if(threadFinished) {
break;
} else {
Sleep(1000);
}
}

After this if the value of "threadFinished" is false then i am terminating the thread like below

if(threadFinished == false) {
TerminateThread(hThread,0);
CloseHandle(hThread);
}

The Problem here is, after terminating the thread, the program abruptly closes by giving fatal error. Looks like memory leakage is happening after terminating the thread. Is it not the right way to safely exit the thread?

View 2 Replies View Related

C++ :: OpenMP - Intervals Assigned To Threads?

Feb 6, 2014

Is there a way of knowing which indices a thread is assigned in a parallel openMP scope?

View 6 Replies View Related

C :: Double Linked Structure Between 2 Threads

Jun 2, 2014

I am on a little project involving TCP socket-programming and multiple threads but need passing structures between two threads.

The first thread receives data with respective ID, temp, etc,.. Each ID is a list-item of a linked list and every ID has again a linked list of all the received data.

The second thread just have to access the list and perform some manipulations on it.

My solution: pass the head pointer of the linked list. Easy enough, right? Somehow, I am stuck receiving error message:" dereferencing pointer to incomplete type."

For the sake of ease and simplicity I just added a stripped down version of the project.

The magic (or not) happens in MainProcess.c: The Data thread should receive the pointer (a think) from the Connection thread.

View 5 Replies View Related

C++ :: Profiling Code - 4 Threads Slower Than 1

May 9, 2013

I am doing something wrong since for me 4 threads perform 2 times slower then 1.I have 2 vectors with bunch of data to process, there is no concurrency (not moving elements and are independent of each other) so i just need to calculate some data from one and copy result in another.

LARGE_INTEGER getFrequency()
{
LARGE_INTEGER frequency;
QueryPerformanceFrequency(&frequency);
return frequency;

[code].....

View 7 Replies View Related

C++ :: Create Two Threads Calling Even And Odd Functions

Mar 1, 2013

I want to create two threads which will be calling even and odd functions where even function should print even number and odd function should print odd number.Can it be possible with condition variable? What is the code in both the cases i.e. two separate function and with condition variable.

View 6 Replies View Related

C Sharp :: Stopping And Resuming Threads?

Jul 9, 2012

how do I stop and restart a Thread in C# once it reaches a certain location on a form then restart the thread once it goes outside of the location boundries?

I am trying to stop an animation thread (a bullet) once it reaches a block on a panel.

View 1 Replies View Related

C++ :: Threads Never Execute In Arbitrary Order?

Jul 25, 2014

Code:

void Arrival_MainThread::Body () {
t1 = new boost::thread((Arrive_Fctor()), 2);
t2 = new boost::thread((Arrive_Fctor()), 10000);
t3 = new boost::thread((Arrive_Fctor()), 3000);

Code:
class Arrive_Fctor {
public:
void operator()(int mean) {
m_Arrivals = new Arrivals(mean);
m_Arrivals->Activate();
#ifndef NO_RESOURCE

[code].....

The order of arrivals always appear as 3,2,1 it can't be 1,2,3 or 3,1,2 or something like that?

The body method is called when m_Arrival->Activate() is executed, and it is running as an independent thread.

View 4 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved