EmbLogic's Blog

Pthread program to understand the working of Thread Semaphore.

RCS file: simple_wait_and_post.c,v
Working file: simple_wait_and_post.c
head: 1.11
branch:
locks: strict
root: 1.11
access list:
symbolic names:
keyword substitution: kv
total revisions: 11;    selected revisions: 11
description:
Code to demonstrate the working of sem_wait and sem_post.
—————————-
revision 1.11    locked by: root;
date: 2014/01/25 06:30:56;  author: root;  state: Exp;  lines: +4 -2
After sem_wait() and sem_post() to see the updated value of semaphore use sem_getvalue() system call.
The result is coming as desired….
—————————-
revision 1.10
date: 2014/01/25 06:27:33;  author: root;  state: Exp;  lines: +4 -0
Now the child thread is executing,previously main thread is terminating before the child thread to finish.
sem_wait() and sem_post() are added to see theie functioning…
—————————-
revision 1.9
date: 2014/01/25 06:24:26;  author: root;  state: Exp;  lines: +1 -0
pthread_join() system call is used to make the main thread wait for the child thread.
Checking….
—————————-
revision 1.8
date: 2014/01/25 06:21:43;  author: root;  state: Exp;  lines: +1 -1
Compilation successfull.
Program is displaying the print statements present in the main threads but not in the child thread.
—————————-
revision 1.7
date: 2014/01/25 06:20:39;  author: root;  state: Exp;  lines: +1 -0
header file:<semaphore.h> is added to support built-in functions.
—————————-
revision 1.6
date: 2014/01/25 06:18:09;  author: root;  state: Exp;  lines: +13 -0
sem_getvalue() and sem_init() system calls are used to initialize and retrieving the value of the thread
semaphore.
—————————-
revision 1.5
date: 2014/01/25 06:12:00;  author: root;  state: Exp;  lines: +5 -0
Prototype of the display() function is given.
A global variable of type sem_t is declared.
Defining the body of the display function……
—————————-
revision 1.4
date: 2014/01/25 06:09:26;  author: root;  state: Exp;  lines: +1 -0
Header file:<pthread.h> is included to support built-in thread functions.
—————————-
revision 1.3
date: 2014/01/25 06:07:53;  author: root;  state: Exp;  lines: +11 -0
A variable of type pthread_t is declared that will store the thread_id.
pthread_create() system call is used to create the thread.
—————————-
revision 1.2
date: 2014/01/25 06:04:43;  author: root;  state: Exp;  lines: +5 -1
Header file:<stdio.h> is added to support I/O functions.
Defining the body of the main thread…
—————————-
revision 1.1
date: 2014/01/25 06:03:50;  author: root;  state: Exp;
Initial revision
=============================================================================

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>