simple thread linux

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <iostream>
#include <stdio.h>
#include <pthread.h>
void* do_loop(void* data) {
int i;
int* me = (int*)data;
for(i = 0; i < 5; i++) {
sleep(1);
printf("'%d' got '%d'\n", *me, i);
}
pthread_exit(NULL);
}
int main() {
int thread_id;
pthread_t p_thread;
int a = 1;
int b = 2;
thread_id = pthread_create(&p_thread, NULL, do_loop, (void*)&a);
do_loop((void*)&b);
return 0;
}