Skip to content

Instantly share code, notes, and snippets.

@stevenleeg
Created May 8, 2013 14:49
Show Gist options
  • Save stevenleeg/5540959 to your computer and use it in GitHub Desktop.
Save stevenleeg/5540959 to your computer and use it in GitHub Desktop.
Playing with threads
#include <pthread.h>
#include <stdio.h>
void count() {
int i = 0;
for(i = 0; i < 10; i++) {
usleep(1);
printf("Counting: %d\n", i);
}
}
int main(void) {
printf("Hello world\n");
pthread_t pth1;
pthread_create(&pth1, NULL, count, NULL);
pthread_t pth2;
pthread_create(&pth2, NULL, count, NULL);
pthread_join(pth1, NULL);
pthread_join(pth2, NULL);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment