LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Blogs > Aquarius_Girl
User Name
Password

Notices


PThreads
Old

Why and how to use condition variables? - Pthreads

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

  • 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:

    Assumptions:
    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 2966 Comments 0 Aquarius_Girl is offline
Old
Rating: 6 votes, 4.83 average.

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

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

  • 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 44402 Comments 0 Aquarius_Girl is offline
Old

Why and how to use Mutex locks - Pthreads

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

Problem:
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 23251 Comments 3 Aquarius_Girl is offline

  



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

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