Created
June 16, 2015 12:50
-
-
Save mosfet1kg/9962b9619156fd83770d to your computer and use it in GitHub Desktop.
test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <pthread.h> | |
char **ptr; /* global */ | |
/* thread routine */ | |
void *thread(void *vargp) | |
{ | |
int64_t myid = (int64_t)vargp; | |
static int cnt = 0; | |
printf("[%d]: %s (svar=%d)\n", | |
myid, ptr[myid], ++cnt); | |
} | |
int main() | |
{ | |
int i; | |
pthread_t tid; | |
char *msgs[2] = { | |
"Hello from foo", | |
"Hello from bar" | |
}; | |
ptr = msgs; | |
for (i = 0; i < 2; i++) | |
pthread_create(&tid, | |
NULL, | |
thread, | |
(void *)i); | |
pthread_exit(NULL); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment