Welcome to the most active Linux Forum on the web.
Go Back > Blogs > TheIndependentAquarius
User Name



Why and how to use condition variables? - Pthreads

Posted 02-06-2013 at 01:40 AM by TheIndependentAquarius
Updated 02-06-2013 at 05:55 AM by TheIndependentAquarius

  • Q: What is a condition variable?
    A: A condition variable is a variable of type `pthread_cond_t`. It is
    used to suspend the thread execution until some condition is true.

  • Q: Is a condition variable dependent on a mutex lock to work properly? Why?
    A: Explaining with an example:

    1. There is a variable `x` whose current value is 0.
    2. There is a thread `threadA` whose task is to start some job once the
      variable `x` reaches the value 1000.
    3. There
Senior Member
Posted in PThreads
Views 1240 Comments 0 TheIndependentAquarius is offline
Rating: 4 votes, 5.00 average.

Why and how to use `pthread_join()`? - PThreads

Posted 05-23-2012 at 01:00 AM by TheIndependentAquarius
Updated 08-24-2012 at 01:50 AM by TheIndependentAquarius

  • Q: What is join with respect to Pthreads?
    A: Join is a functionality of Pthread library which allows the originating thread to wait for the completion of all its spawned thread's tasks.

    Without join the originating thread would exit as soon as it completes its chores, completely ignoring the states of its spawned threads. Due to this, even if any of the spawned threads is in middle of its chore, it'll simply get aborted.
  • Problem statement:
    In the below code I have
Senior Member
Posted in PThreads
Views 11723 Comments 0 TheIndependentAquarius is offline

Why and how to use Mutex locks - Pthreads

Posted 02-27-2012 at 11:06 AM by TheIndependentAquarius
Updated 05-21-2012 at 01:51 AM by TheIndependentAquarius

Underlying operating system may schedule the threads on the basis of some algorithm which works on time limit (threads may be allowed to run only for certain durations of time, thus preventing the other threads from starvation), priority (higher priority threads may interrupt the lower priority threads during their execution), or some other factor.

These factors may cause a thread to sleep before it completes its task fully. Another thread may get scheduled meanwhile...
Senior Member
Posted in PThreads
Views 15838 Comments 3 TheIndependentAquarius is offline


All times are GMT -5. The time now is 09:50 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration