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
This is a discussion on semaphores help within the Linux Programming forums, part of the Platform Specific Boards category; i created 11 threads..... and each thread is doing a function the 11th thread should execute after all the 10 ...
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.
The first 90% of a project takes 90% of the time,
the last 10% takes the other 90% of the time.
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.
I support http://www.ukip.org/ as the first necessary step to a free Europe.
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