Created
September 30, 2014 05:57
-
-
Save i/622c4c7649029428732e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <pthread.h> | |
#define THREAD_COUNT 30 | |
// Each thread will run an | |
// instance of this function | |
void *worker(void *arg) { | |
printf("I'm worker #%d\n", (int)arg); | |
return NULL; | |
} | |
// In this example, pthreads are created and joined | |
// on immediately. This will prevent any race conditions | |
// but also prevent any concurrency, so it's pointless. | |
int main(int argc, char *argv[]) { | |
int i, failure; | |
pthread_t thread_pool[THREAD_COUNT]; // Array of threads | |
for (i = 0; i < THREAD_COUNT; i++) { | |
failure = pthread_create(&thread_pool[i], NULL, &worker, (int*)i); | |
pthread_join(thread_pool[i], NULL); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment