Skip to content

Instantly share code, notes, and snippets.

@tarunjain07
Created April 8, 2018 13:38
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 tarunjain07/7e815c77b2ece08c694fa3f1e5b4d58f to your computer and use it in GitHub Desktop.
Save tarunjain07/7e815c77b2ece08c694fa3f1e5b4d58f to your computer and use it in GitHub Desktop.
/* PThread Creation */
#include <stdio.h>
#include <pthread.h>
void *foo (void *arg) { /* thread main */
printf("Foobar!\n");
pthread_exit(NULL);
}
int main (void) {
int i;
pthread_t tid;
pthread_attr_t attr;
pthread_attr_init(&attr); // Required!!!
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM);
pthread_create(&tid, &attr, foo, NULL);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment