some thread API examples
This commit is contained in:
25
threads-api/thread_create.c
Normal file
25
threads-api/thread_create.c
Normal file
@@ -0,0 +1,25 @@
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <pthread.h>
|
||||
|
||||
typedef struct {
|
||||
int a;
|
||||
int b;
|
||||
} myarg_t;
|
||||
|
||||
void *mythread(void *arg) {
|
||||
myarg_t *args = (myarg_t *) arg;
|
||||
printf("%d %d\n", args->a, args->b);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
pthread_t p;
|
||||
myarg_t args = { 10, 20 };
|
||||
|
||||
int rc = pthread_create(&p, NULL, mythread, &args);
|
||||
assert(rc == 0);
|
||||
(void) pthread_join(p, NULL);
|
||||
printf("done\n");
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user