Skip to content

Instantly share code, notes, and snippets.

@mstrYoda
Created October 19, 2016 11:32
Show Gist options
  • Save mstrYoda/4d7605de3c81b52c1d7c0e7880daca27 to your computer and use it in GitHub Desktop.
Save mstrYoda/4d7605de3c81b52c1d7c0e7880daca27 to your computer and use it in GitHub Desktop.
pthread join sample
#include "stdafx.h"
#include <cstdlib>
#include <iostream>
#define HAVE_STRUCT_TIMESPEC
// posix thread kütüphanesi
#include <pthread.h>
void *print_message_function(void *ptr);
int main() {
pthread_t thread1, thread2;
char *message1 = "Thread 1";
char *message2 = "Thread 2";
int iret1, iret2;
iret1 = pthread_create(&thread1,NULL,print_message_function,(void *)message1);
iret2 = pthread_create(&thread2, NULL, print_message_function, (void *)message2);
//pthread_join(thread1,NULL);
pthread_join(thread2, NULL);
printf("Thread1 returns: %d\n",iret1);
printf("Thread2 returns: %d\n", iret2);
system("pause");
exit(0);
return -1;
}
void * print_message_function(void * ptr)
{
char *message;
message = (char *)ptr;
printf("%s \n",message);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment