Click here to Skip to main content
13,247,891 members (41,453 online)
Rate this:
Please Sign up or sign in to vote.
See more:

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

Posted 3-Jan-13 19:30pm
Aha, 1, 2 or 3? Looks like yet another... original interview question :-)
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.
pwasser 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?
...and you are faking your "answers", please stop doing it.
Rate this: bad
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[^].
Rate this: bad
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.[^]
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

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

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web04 | 2.8.171114.1 | Last Updated 4 Jan 2013
Copyright © CodeProject, 1999-2017
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