Skip to content

Commit

Permalink
Added basic threading code to thread-simple
Browse files Browse the repository at this point in the history
  • Loading branch information
jjolly committed Feb 16, 2018
1 parent 95cb4fc commit aa079d0
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions threads/simple/simple.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,31 @@
#include<stdio.h>
#include<pthread.h>

/* Simple child thread function */
void *child_thread_func(void *p) {
printf("Child thread created\n");
return NULL;
}

int main(int argc, char *argv[]) {
/* Thread handle */
pthread_t thread_handle;
int ret;

/* Create child thread */
ret = pthread_create(&thread_handle, NULL, child_thread_func, NULL);

if(ret != 0) {
fprintf(stderr, "Error creating child thread\n");
return -1;
}

ret = pthread_join(thread_handle, NULL);

if(ret != 0) {
fprintf(stderr, "Error joining child thread\n");
return -1;
}

return 0;
}

0 comments on commit aa079d0

Please sign in to comment.