Results 1 to 3 of 3
Hi,All
im using WaitForMultipleObjects in windows,but my questions is how to do the same in linux since there is no equivalent api in linux.....
(since i need my threads to ...
- 10-17-2011 #1Just Joined!
- Join Date
- Sep 2011
- Posts
- 4
WaitForMultipleObjects equivalent in linux
Hi,All
im using WaitForMultipleObjects in windows,but my questions is how to do the same in linux since there is no equivalent api in linux.....
(since i need my threads to wait for the event to trigger)
Here is my code
please help in fixing this issueCode:long PredictThread(const Array2D<REAL> &X) { if (X.dim2()!=m_NumVars) return -1; long i,j; Array3D<REAL> Ypred(X.dim1(),m_Categories.size(), 6, 0.0); HANDLE* TID = new HANDLE[m_Categories.size()]; DWORD ThreadID; TParam* pOTParam = new TParam[m_Categories.size()]; TParam* pTParam = pOTParam; for(j=0;j<m_Categories.size();++j) { TParam* pParam = pTParam; pParam->category = j; pParam->model = m_Categories[j]; pParam->X = X.copy(); pParam->Ypred = Ypred; TID[j] = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)ThreadProc,(LPVOID)pParam,0,&ThreadID); pTParam++; } WaitForMultipleObjects(m_Categories.size(), TID, TRUE, INFINITE); for(j=0;j<m_Categories.size();++j) CloseHandle(TID[j]); delete [] TID; delete [] pOTParam; m_members = Ypred; return 0; }
thanking you ....................
- 10-17-2011 #2Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 8,974
Assuming you are using posix threads (pthreads), you may be able to use pthread_cond_wait() to simulate this Windows function. You should carefully read and understand the pthreads documentation before you continue. There is quite a bit of information in the man pages (see "man pthreads" and the man pages for other pthread functions and structures) which will help you use these api's.
Sometimes, real fast is almost as good as real time.
Just remember, Semper Gumbi - always be flexible!
- 10-18-2011 #3Just Joined!
- Join Date
- Jan 2011
- Location
- Fairfax, Virginia, USA
- Posts
- 94
Hi Shams
Just to augment what Rubberman passed on, if you want your code to be cross platform so one set of code compiles on both Linux and Windows, you can use this package on Windows:
POSIX Threads (pthreads) for Win32
I use it and it works pretty well. You can compile the library statically and link against the static image if you want. Some features which aren't used often (like pthread_yield() for instance()) aren't implemented. If you read the forms, people are skeptical of this library because it doesn't get much development attention but it works well (I think ffmpeg uses this library BTW).


Reply With Quote