49 lines
926 B
C
49 lines
926 B
C
|
|
#include <assert.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
#include <pthread.h>
|
|
|
|
void *
|
|
thread_simple(void *arg)
|
|
{
|
|
printf("thread_simple %p!\n", arg);
|
|
|
|
return arg;
|
|
}
|
|
|
|
int
|
|
main(int argc, const char *argv[])
|
|
{
|
|
int status;
|
|
pthread_t thr;
|
|
void *result;
|
|
|
|
printf("PThread Test\n");
|
|
|
|
// Simple thread test
|
|
printf("simple test\n");
|
|
status = pthread_create(&thr, NULL, thread_simple, NULL);
|
|
printf("status %d\n", status);
|
|
assert(status == 0);
|
|
status = pthread_join(thr, &result);
|
|
printf("status %d\n", status);
|
|
assert(status == 0);
|
|
assert(result == NULL);
|
|
|
|
// Return value test
|
|
printf("return value test\n");
|
|
status = pthread_create(&thr, NULL, thread_simple, (void *)1);
|
|
assert(status == 0);
|
|
status = pthread_join(thr, &result);
|
|
assert(status == 0);
|
|
assert(result == (void *)1);
|
|
|
|
printf("Success!\n");
|
|
|
|
return 0;
|
|
}
|
|
|