2013-04-16 23:57:53 -04:00
|
|
|
#include <toku_portability.h>
|
2013-04-16 23:57:27 -04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <assert.h>
|
2013-04-16 23:57:30 -04:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <toku_pthread.h>
|
2013-04-16 23:57:27 -04:00
|
|
|
|
|
|
|
static void *myfunc1(void *arg) {
|
|
|
|
printf("%s %p %lu\n", __FUNCTION__, arg, GetCurrentThreadId());
|
|
|
|
fflush(stdout);
|
2013-04-16 23:57:30 -04:00
|
|
|
sleep(10);
|
2013-04-16 23:57:27 -04:00
|
|
|
return arg;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void *myfunc2(void *arg) {
|
|
|
|
printf("%s %p %lu\n", __FUNCTION__, arg, GetCurrentThreadId());
|
|
|
|
fflush(stdout);
|
2013-04-16 23:57:30 -04:00
|
|
|
sleep(10);
|
2013-04-16 23:57:27 -04:00
|
|
|
return arg;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(void) {
|
|
|
|
#define N 10
|
|
|
|
toku_pthread_t t[N];
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i=0; i<N; i++) {
|
|
|
|
toku_pthread_create(&t[i], NULL, i & 1 ? myfunc1 : myfunc2, (void *)i);
|
|
|
|
}
|
|
|
|
for (i=0; i<N; i++) {
|
|
|
|
void *ret;
|
|
|
|
toku_pthread_join(t[i], &ret);
|
|
|
|
assert(ret == (void*)i);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|