EmbLogic's Blog

Creating two threads which then display two different messages untill a condition is satisfied and making the main thread to wait for them to finish.

RCS file: simple_thread.c,v
Working file: simple_thread.c
head: 1.14
branch:
locks: strict
root: 1.14
access list:
symbolic names:
keyword substitution: kv
total revisions: 14;    selected revisions: 14
description:
A simple thread program in which 2 threads are created and 2 separate
messages are displayed by them.
—————————-
revision 1.14    locked by: root;
date: 2014/01/22 03:00:52;  author: root;  state: Exp;  lines: +1 -0
pthread_join() system call is added in the main thread to wait for the second thread to finish.
—————————-
revision 1.13
date: 2014/01/22 02:55:41;  author: root;  state: Exp;  lines: +2 -2
Errors like missing semicolons and variable undeclared fixed.
Checking…the functionality.
—————————-
revision 1.12
date: 2014/01/22 02:53:36;  author: root;  state: Exp;  lines: +23 -3
A second thread is created in the same program.
A different function is prepared with a different message.
pthread_join() is not added in the main thread for the second thread.
—————————-
revision 1.11
date: 2014/01/22 02:44:46;  author: root;  state: Exp;  lines: +2 -1
pthread_join() system call is added to inform the main thread to wait for the thread
with thread-id to finish.If this is not done the main thread does its work and terminates,
without checking any other thread is working or not.
—————————-
revision 1.10
date: 2014/01/22 02:35:06;  author: root;  state: Exp;  lines: +2 -1
pthread_self() system call is added to obtain the thread’s ID.
—————————-
revision 1.9
date: 2014/01/22 02:03:40;  author: root;  state: Exp;  lines: +2 -1
Terminating the main thread using pthread_exit() system call.
—————————-
revision 1.8
date: 2014/01/22 02:00:33;  author: root;  state: Exp;  lines: +5 -0
pthread_exit() system call is added in the program to terminate the
thread after 8 seconds.
—————————-
revision 1.7
date: 2014/01/22 01:51:28;  author: root;  state: Exp;  lines: +6 -4
sleep() system call is added in the thread’s display_func1().
The thread is getting terminated due to the main thread performing a return.
—————————-
revision 1.6
date: 2014/01/22 01:44:42;  author: root;  state: Exp;  lines: +16 -2
A check is added to see if the thread is created successfully.
Adding sleep() system call to analyse the output.
—————————-
revision 1.5
date: 2014/01/22 01:35:38;  author: root;  state: Exp;  lines: +4 -0
Definition for the display_func1() function is included.
—————————-
revision 1.4
date: 2014/01/22 01:31:09;  author: root;  state: Exp;  lines: +1 -0
Prototype for the display_func1() is added.
This function will display the message for thread1.
It will also display the thread_id.
—————————-
revision 1.3
date: 2014/01/22 01:29:21;  author: root;  state: Exp;  lines: +2 -0
header file:<pthread.h> is included to support pthread_create() system call.
—————————-
revision 1.2
date: 2014/01/22 01:25:54;  author: root;  state: Exp;  lines: +1 -0
Two variables of pthread_t type are declared that will store the thread_ids.
—————————-
revision 1.1
date: 2014/01/22 01:23:36;  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>