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.
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?
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
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.
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?
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...
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?
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?
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?
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 ?
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.
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.
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?
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.
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?
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 ?
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
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?
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.
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.
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.
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.
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.