2009年9月20日 星期日

pthread example

void *Test(void *threadid)
{
long tid;
tid = (long)threadid;
printf("Hello World! It's me, thread #%ld!\n", tid);
pthread_exit(NULL);
}

int main (int argc, char *argv[])
{
pthread_t myThread;
int rc;
long t;
printf("In main: creating thread %ld\n", t);
rc = pthread_create(&myThread, NULL, Test, (void *)t);
if (rc){
printf("ERROR; return code from pthread_create() is %d\n", rc);
exit(-1);
}
pthread_exit(NULL);
}

沒有留言:

張貼留言