Link to home
Start Free TrialLog in
Avatar of net3phone
net3phone

asked on

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
}

Avatar of NT_Programmer
NT_Programmer

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


Avatar of net3phone

ASKER

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
}

ASKER CERTIFIED SOLUTION
Avatar of NT_Programmer
NT_Programmer

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
Hi NT Programmer
I want source code of this example if possible using c++ builder 3