Skip to content

Instantly share code, notes, and snippets.

@hamadu
Created August 7, 2017 16:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hamadu/f1b090ce84108494a1176b2a350a859d to your computer and use it in GitHub Desktop.
Save hamadu/f1b090ce84108494a1176b2a350a859d to your computer and use it in GitHub Desktop.
thread
#include <unistd.h>
#include <stdio.h>
#include <pthread.h>
int global_num = 100;
void* another(void *arg) {
global_num = 200;
printf("hello from another thread: %d\n", global_num);
global_num = 300;
}
int main(int argc, char* argv[]) {
pthread_t thread;
pthread_create(&thread, NULL, *another, NULL);
sleep(3);
printf("hello from main thread: %d\n", global_num);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment