#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);
}

plz explain it as soon as possible its very urgent 4 me

Tell you what. You comment each line whith what you think it means and we'll help you correct it.

And use CODE tags!!!

commented: well said +17

i want to know what is this program doing.. its working is un understandable

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.