Os and networking Lab programs

June 4, 2010

Threads

Filed under: Operating Systems,Theory needed for implementing OS related problems — osandnetworkingcslab @ 1:23 am

  • GNU/Linux implements the POSIX standard thread API (known as pthreads). All thread functions and data types are declared in the header file <pthread.h>.

Pthreads defines a set of programming C language types, functions and constants. It is implemented with a header and a thread library. Programmers can use Pthreads to create, manipulate and manage threads, as well as between threads using mutex. Mutex variables are one of the primary means of implementing thread synchronization and for protecting shared data when multiple writes occur. A mutex variable acts like a “lock” protecting access to a shared data resource. The basic concept of a mutex as used in Pthreads is that only one thread can lock (or own) a mutex variable at any given time. Thus, even if several threads try to lock a mutex only one thread will be  successful. No other thread can own that mutex until the owning thread unlocks that mutex. Threads must “take turns” accessing protected data.

    Leave a Comment »

    No comments yet.

    RSS feed for comments on this post. TrackBack URI

    Leave a comment

    Blog at WordPress.com.