Click here to Skip to main content
15,896,348 members
Please Sign up or sign in to vote.
1.36/5 (4 votes)
See more:
Hi,

I would like to know, In how many ways can a thread be kept in waiting state.

Cheers..!!
Posted
Comments
Sergey Alexandrovich Kryukov 4-Jan-13 0:41am    
Aha, 1, 2 or 3? Looks like yet another... original interview question :-)
—SA
Baddy_Bad_Boy 4-Jan-13 2:06am    
Not really, A kind of...
any fixed answer for the question.
Richard MacCutchan 4-Jan-13 5:14am    
Probably an infinite number, as a thread could be made to wait for any possible event to occur.
Baddy_Bad_Boy 4-Jan-13 23:32pm    
well Richard, I appreciate your answer but, can you please elaborate it.
I was pretty much interested to know how a thread can be kept to wait.
I found some keywords through CPallini below.
[no name] 6-Jan-13 4:07am    
Until you turn this into a proper question it can't be answered. Explain what you are trying to do. Putting a thread into a "wait state" just for the hell of it has no point. Why does the thread exist at all?

There are several ways, for instance a thread might be waiting on blocking input call or it might be unconditionally sleeping.
The recommended way to put a POSIX thread in wait state is using a condition variable, see Condition Variables[^].
 
Share this answer
 
1)int pthread_join(pthread_t th, void **thread_return);

The pthread_join function is used to wait for termination of a thread --- or wait for the thread to re-join the main thread.


http://www.amparo.net/ce155/thread-ex.html[^]
 
Share this answer
 
Using semaphores or Mutex, the threads can be made to wait.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900