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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
NT_ProgrammerCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.