multi threads using flag

I want source code to the multi threads
like this example using flag
using c++ Builder3.
 thread1:-
// execute

for(;;)
{
 statements
 passing flag to  another thread
(thread2)to resume;

}
thread2:
 //execute
 for(;;)
{
 wait until thread1 passing flag to resume
 statements
 suspend
}

net3phoneAsked:
Who is Participating?
 
NT_ProgrammerConnect With a Mentor Commented:
In your particular case you may not need two threads.  Why have one wait for the other?  It may be just as easy for thread one to complete the second thread's work instead of passing it to another thread.

The whole idea about having threads is that two separate functionalities can be performed _at the same time_, not for one to wait for the other to do something, then you are only performing single-threaded functionality.
0
 
NT_ProgrammerCommented:
In thread one:
hEvent = CreateEvent( NULL, TRUE, FALSE, NULL);

for( ; ; )
{
   // whenever you are ready for thread 2 to pause
   ::ResetEvent( hEvent );

   // whenever you are ready for thread 2 to run:
   ::SetEvent( hEvent );
}

In thread two do this:

for( ; ; )
{
   //Pauses until ::SetEvent( ) is called
   ::WaitForSingleObject( hEvent );
}

so in thread 1 any time you call ResetEvent( ) thread 2 will stop on that ::WaitForSingleObject call until ::SetEvent( ) gets called again


0
 
net3phoneAuthor Commented:
i use this example to chatting voice like while recording and save i want to send file and i have two synchronize threads in thread one
for (;;)
{statements;
walk the thread two;
}
in thread two :-
|wait until the thread one walk it
for (;;)
{
statement;
|wait until the thread one walk it
}

0
 
net3phoneAuthor Commented:
hi NT programmer :-
in thread one uses some steps after the ending steps i resume the steps ,but in the thread two must wait the last steps in thread one to resume and wait again until thread two complete last step.  
I want source code if possible
thanks
0
 
net3phoneAuthor Commented:
Hi NT Programmer
I want source code of this example if possible using c++ builder 3
0
All Courses

From novice to tech pro — start learning today.