#include <sys/types.h>
#include <sys/wait.h>
#include <stdio.h>
#include <unistd.h>
void *thread(void *vargp);
char **ptr; /* global */
int main()
{
int i;
pthread_t tid;
char *msgs[2] = {
"Hello from Thread A",
"Hello from Thread B"
};
ptr = msgs;for (i = 0; i < 2; i++)
pthread_create(&tid,NULL,thread,(void *)i);
pthread_exit(NULL);
}
/* thread routine */
void *thread(void *vargp)
{
int myid = (int)vargp;
static int svar = 0;
printf("[%d]: %s (svar=%d)\n",
myid, ptr[myid], ++svar);
}
kainat0615 0 Newbie Poster
kainat0615 0 Newbie Poster
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
Salem commented: well said +17
kainat0615 0 Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.