Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ Linux
Hi,

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

Cheers..!!
Posted 3-Jan-13 19:30pm
Comments
Sergey Alexandrovich Kryukov at 4-Jan-13 0:41am
   
Aha, 1, 2 or 3? Looks like yet another... original interview question :-)
—SA
Baddy_Bad_Boy at 4-Jan-13 2:06am
   
Not really, A kind of...
any fixed answer for the question.
Richard MacCutchan at 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 at 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.
pwasser at 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?
Sergey Alexandrovich Kryukov at 3-Jul-13 10:29am
   
...and you are faking your "answers", please stop doing it.
—SA
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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[^].
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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[^]
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Using semaphores or Mutex, the threads can be made to wait.
  Permalink  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 6,534
1 OriginalGriff 6,258
2 Peter Leow 2,534
3 Maciej Los 2,308
4 Abhinav S 2,274


Advertise | Privacy | Mobile
Web04 | 2.8.150414.1 | Last Updated 4 Jan 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100