-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added basic threading code to thread-simple
- Loading branch information
Showing
1 changed file
with
28 additions
and
0 deletions.
There are no files selected for viewing
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
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; | ||
} |