Coding/CPP 삽질기
[CPP] Linux Thread Example Code
chobocho
2008. 12. 14. 21:49
#include <stdio.h>
#include <pthread.h>
void *Count (void *);
int main(int argc, char **argv)
{
pthread_t p_thread[2];
int pthread_status;
pthread_create(&p_thread[0], NULL, Count, (void *)NULL);
pthread_create(&p_thread[1], NULL, Count, (void *)NULL);
pthread_join(p_thread[0], (void **)&pthread_status);
pthread_join(p_thread[1], (void **)&pthread_status);
return 0;
}
void *Count (void *arg)
{
pthread_t thread_id = pthread_self();
int num = 0;
while (num < 10)
{
printf ("%x : %d\n", thread_id, num);
num++;
sleep(1);
}
}