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