Skip to content

Instantly share code, notes, and snippets.

@ozgurkaracam
Created May 29, 2015 07:45
Show Gist options
  • Save ozgurkaracam/88fbc1433746c0238f76 to your computer and use it in GitHub Desktop.
Save ozgurkaracam/88fbc1433746c0238f76 to your computer and use it in GitHub Desktop.
thread1
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <pthread.h>
#define NUMBER_OF_THREADS 10
void *
print_hello_world(void *tid)
{
/* This function prints the thread's identifier and then exits. */
printf("Merhaba Dünya [evre: %d]\n", (intptr_t)tid);
pthread_exit(NULL);
}
int
main(int argc, char *argv[])
{
pthread_t threads[NUMBER_OF_THREADS];
int status, i;
for (i = 0; i < NUMBER_OF_THREADS; i++) {
printf("Evre %d oluşturuluyor [main işlevi]\n", i);
status = pthread_create(&threads[i], NULL, print_hello_world, (void *)(intptr_t)i);
if (status != 0) {
fprintf(stderr, "Hata pthread_create: %d\n", status);
exit(EXIT_FAILURE) ;
}
}
for (i = 0; i < NUMBER_OF_THREADS; i++) {
status = pthread_join(threads[i], NULL);
if (status != 0) {
fprintf(stderr, "Hata pthread_join: %d\n", status);
exit(EXIT_FAILURE) ;
}
}
exit(EXIT_SUCCESS);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment