i created 11 threads..... and each thread is doing a function the 11th thread should execute after all the 10 thread processing is over iam using semaphore for this i need help... in doing this
i created 11 threads..... and each thread is doing a function the 11th thread should execute after all the 10 thread processing is over iam using semaphore for this i need help... in doing this
On windows:
You can just use the WaitForMultipleObjects function passing the array of thereads' handles.
If you set bWaitAll parameter to true, this function will exit when all threads, whose handles are present in the array, are finished.
All problems in computer science can be solved by another level of indirection,
except for the problem of too many layers of indirection.
– David J. Wheeler
thanks vart but iam working on red hat linux can u suggest using semaphore functions
So post your attempt at using semaphores then.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
In Linux (as I know) there is no semaphore type other than binary semaphores. You have mutex primitive in hand from pthread API. You have to implement your own counting semaphore type.
I am sure that you can find any implementation of counting semaphores from binary semaphores.
Linux has arbitrary value semaphores. Look at the sem_* family of functions.
But a semaphore is not the right tool for this job. vart's approach of actually waiting for thread termination is better. You can use pthread_join() for this if you use pthreads in the first place.
All the buzzt!
CornedBee
"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
- Flon's Law