some thread API examples

This commit is contained in:
Remzi Arpaci-Dusseau
2019-04-23 12:12:17 -05:00
parent b4fa80ad67
commit 502a67f965
5 changed files with 121 additions and 0 deletions

View 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;
}