Skip to content

Instantly share code, notes, and snippets.

@mosfet1kg
Created June 16, 2015 12:50
Show Gist options
  • Save mosfet1kg/9962b9619156fd83770d to your computer and use it in GitHub Desktop.
Save mosfet1kg/9962b9619156fd83770d to your computer and use it in GitHub Desktop.
test
#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