Kohinoor24
September 17th, 2002, 06:39 AM
I have an application which have to be run under Windows as well as Linux.It is a multithreaded application also.
Iam having problems(Run Time Errror) Exiting with the threads in Linux when it comes to the pthread_join statement.
The Windows side runs well.I have implemented it under windows & Linux as follows.
Could anyone tell me what should be done under Linux Side for safely exiting the threads
Thanks in advance....
For Windows:
------------
thread_write->Start();
thread_read->Start();
// Getting Thread Handles.
HANDLE hHandles[2] = {thread_write->GetHandle(),thread_read->GetHandle()};
int NumThreads = 2;
do
{
switch(WaitForMultipleObjects(NumThreads,hHandles,false,INFINITE))
{
case WAIT_OBJECT_0 +0:
if(hHandles[0]==thread_write->GetHandle())
m_Readaccess->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:
hHandles[0]= hHandles[--NumThreads];
break;
}
}
while(NumThreads)
For Linux:
----------
typedef WriterThread<LinuxThread> WriterThread;
typedef ReaderThread<LinuxThread> ReaderThread;
m_pCycleBuffer = new T_BUFFERTYPE(BUF_SIZE);
m_BasePtr = new LinuxThread();
m_Readaccess = new C_BufferReadAccess(*m_pCycleBuffer,* m_BasePtr);
WriterThread *thread_write = new WriterThread(*m_pCycleBuffer,*m_pdma,* m_RdiFilename,*m_pmta);
ReaderThread *thread_read = new ReaderThread(*m_pCycleBuffer,*m_pida,*m_Readaccess);
thread_write->Start();
thread_read->Start();
void *status = NULL;
pthread_join(thread_write->GetHandle(),&status);
pthread_join(thread_read->GetHandle(),&status);
Iam having problems(Run Time Errror) Exiting with the threads in Linux when it comes to the pthread_join statement.
The Windows side runs well.I have implemented it under windows & Linux as follows.
Could anyone tell me what should be done under Linux Side for safely exiting the threads
Thanks in advance....
For Windows:
------------
thread_write->Start();
thread_read->Start();
// Getting Thread Handles.
HANDLE hHandles[2] = {thread_write->GetHandle(),thread_read->GetHandle()};
int NumThreads = 2;
do
{
switch(WaitForMultipleObjects(NumThreads,hHandles,false,INFINITE))
{
case WAIT_OBJECT_0 +0:
if(hHandles[0]==thread_write->GetHandle())
m_Readaccess->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:
hHandles[0]= hHandles[--NumThreads];
break;
}
}
while(NumThreads)
For Linux:
----------
typedef WriterThread<LinuxThread> WriterThread;
typedef ReaderThread<LinuxThread> ReaderThread;
m_pCycleBuffer = new T_BUFFERTYPE(BUF_SIZE);
m_BasePtr = new LinuxThread();
m_Readaccess = new C_BufferReadAccess(*m_pCycleBuffer,* m_BasePtr);
WriterThread *thread_write = new WriterThread(*m_pCycleBuffer,*m_pdma,* m_RdiFilename,*m_pmta);
ReaderThread *thread_read = new ReaderThread(*m_pCycleBuffer,*m_pida,*m_Readaccess);
thread_write->Start();
thread_read->Start();
void *status = NULL;
pthread_join(thread_write->GetHandle(),&status);
pthread_join(thread_read->GetHandle(),&status);