From ffabf8a4c7ae99de2c1d15ea2dac04edd72ce20d Mon Sep 17 00:00:00 2001 From: vlizak Date: Sat, 9 Dec 2017 14:19:25 +0100 Subject: [PATCH] Initial commit --- .gitignore | 1 + README.md | 1 + main.cpp | 41 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 43 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 main.cpp diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c056e6b --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +main.out diff --git a/README.md b/README.md new file mode 100644 index 0000000..60f09bc --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +First Concurrent Project diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..e1a9c58 --- /dev/null +++ b/main.cpp @@ -0,0 +1,41 @@ +include +#include +#include + +void* print_message_function(void* ptr); + +main(void) { + pthread_t thread1, thread2; + const char *message1 = "Thread 1"; + const char *message2 = "Thread 2"; + int iret1, iret2; + + iret1 = pthread_create( &thread1, NULL, print_message_function, (void*) message1); + if ( iret1 ) + { + fprintf(stderr, "Error - pthread() return code: %d\n", iret1); + exit(EXIT_FAILURE); + } + + iret2 = pthread_create( &thread2, NULL, print_message_function, (void*) message2); + if ( iret2 ) + { + fprintf(stderr, "Error - pthread() return code: %d\n", iret2); + exit(EXIT_FAILURE); + } + + printf("pthread_create() for thread 1 returns: %d\n", iret1); + printf("pthread_create() for thread 2 returns: %d\n", iret2); + + pthread_join( thread1, NULL); + pthread_join( thread2, NULL); + + exit(EXIT_SUCCESS); +} + +void* print_message_function(void* ptr) +{ + char* message; + message = (char* ) ptr; + printf("%s \n", message); +}