Skip to content

Instantly share code, notes, and snippets.

@tlehman
Created January 6, 2020 17:59
Show Gist options
  • Save tlehman/c850d814b7e50b852db6e72aa3c07938 to your computer and use it in GitHub Desktop.
Save tlehman/c850d814b7e50b852db6e72aa3c07938 to your computer and use it in GitHub Desktop.
Minimal working example of using threads in C
#include <pthread.h>
#include <stddef.h>
#include <stdio.h>
void *entry_point_0(void * input) {
printf("Thread 0 started\n");
sleep(10);
printf("Thread 0 finished\n");
}
void *entry_point_1(void * input) {
printf("Thread 1 started\n");
sleep(8);
printf("Thread 1 finished\n");
}
int main() {
pthread_t thread0;
pthread_t thread1;
pthread_create(&thread0, NULL, entry_point_0, NULL);
pthread_create(&thread1, NULL, entry_point_1, NULL);
pthread_join(thread1, NULL);
pthread_join(thread0, NULL);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment