mikejd42 wrote: > --- In [email protected], "alisha.cruise" <[EMAIL PROTECTED]> wrote: >> You can use a Mutex to solve the problem, >> or you can make one thread wait until the other thread finishes its >> operation... >> >> >> http://programmingsite.googlepages.com >> http://plainthought.googlepages.com >> >> --- In [email protected], "mikejd42" <mikejd42@> wrote: >>> I have two threads both kicked off at the same time. Thread one feeds >>> information info a structure while thread two reads that information. >>> >>> I would imagine that there is some kind of thread lock that I can call >>> to keep thread 2 at bay until thread one has updated the structure? >>> >>> TIA >>> mike >>> > > I need to add more information: > Each of the two pthreads are launched from main. Each pthread stays > in a infinite loop. One of the pthreads listens on a socket for > incoming information from other servers (this could be many) and > populates several structures with the information. The second pthread > analyzes the information in the structures and if needed updates the > other servers. Since both pthread launch at the same time the thread > that is analyzing the data could attempt to grab data that is not > fully obtained yet which reeks havoc on the computations. I would be > able to re-write the routines and call one thread from inside the > other but that would eat more processing power in thread creation and > destruction. Besides you never know what the future will hold so need > to grasp a better understanding of how to control this beast "pthreads". > > Thanks > <mike>
As I said earlier - the general solution is a mutex. main() should create the mutex and then the two threads. Problem solved. -- Thomas Hruska CubicleSoft President Ph: 517-803-4197 *NEW* MyTaskFocus 1.1 Get on task. Stay on task. http://www.CubicleSoft.com/MyTaskFocus/
