RCS file: thrd.c,v
Working file: thrd.c
head: 1.1
branch:
locks: strict
root: 1.1
access list:
symbolic names:
keyword substitution: kv
total revisions: 1; selected revisions: 1
description:
creating the thread
—————————-
revision 1.1 locked by: root;
date: 2014/06/03 06:37:40; author: root; state: Exp;
Initial revision
=============================================================================
RCS file: thrd.c,v
Working file: thrd.c
head: 1.1
branch:
locks: strict
root: 1.1
access list:
symbolic names:
keyword substitution: kv
total revisions: 1; selected revisions: 1
description:
creating the thread
—————————-
revision 1.1 locked by: root;
date: 2014/06/03 06:37:40; author: root; state: Exp;
Initial revision
=============================================================================
#include<stdio.h>
//#include<string.h>
#include<unistd.h>
#include<pthread.h>
//#include<sys/ipc.h>
void *thread_function(void *arg);
char mssg[]=”hi there”;
int main()
{
pthread_t var[20];
void *thrd_rslt;
int ret = pthread_create(&var[20],NULL,thread_function,(void *)mssg);
if(ret!=0)
{
perror(“creation failed”);
// exit(EXIT_FAILURE);
return -1;
}
printf(” i got it……\n”);
printf(“thred created……\n”);
printf(“waiting for thread to finish………>>>>>>>\n”);
ret=pthread_join(var[20],&thrd_rslt);
if(ret!=0)
{
perror(“joining failed”);
//exit(EXIT_FAILURE);
return -1;
}
printf(“thread join returned %s\n”,(char *)thrd_rslt);
printf(“now message is %s\n”,mssg);
//exit(EXIT_SUCCESS);
return 0;
}
void *thread_function(void *arg)
{
printf(“thread function is running with arg %s\n”,(char*)arg);
sleep(2);
strcpy(mssg,”bye”);
pthread_exit(“thanks for cpu time>>>>>>>\n”);
}