Click to See Complete Forum and Search --> : Threading -Linux


Kohinoor24
July 3rd, 2002, 09:55 AM
Iam creating 2 threads-> thread_write & thread_read
& Iam doing as follows to make both the threads exit gracefully.This works on windows platform.

Now I want to make it work on Linux.Iam using pthreads for linux . Is there any libraray routine similar to
"WaitForMultipleObjects" & "HANDLE"(Which are there in windows) in linux-pthreads.

I want 2 things similar to these.


// Allow threads to finish their work and exit gracefully
do
{
switch ( WaitForMultipleObjects(NumThreads, hHandles, false,
INFINITE) )
{
case WAIT_OBJECT_0:
if ( hHandles[0] == thread_write->GetHandle() )
thread_read->SetExitFlag(); // Write thread
//terminated - so allow reader to exit gracefully

// Put last handle in where this one completed and
// reduce number of handles in array
hHandles[0] = hHandles[--NumThreads];
break;
default:
// Put last handle in where this one completed and
// reduce number of handles in array
hHandles[0] = hHandles[--NumThreads];
break;
}
} while ( NumThreads );
}

Thanks in advance
Mohammed