mirror of
https://github.com/Hizenberg469/MultiThreading_Part_A.git
synced 2026-04-19 18:12:24 +03:00
Semaphore Hello World
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -39,7 +39,7 @@
|
||||
"RelativeDocumentMoniker": "ProducerConsumerProblem.c",
|
||||
"ToolTip": "E:\\MultiThreading_Part_A\\ProducerConsumerProblem\\ProducerConsumerProblem.c",
|
||||
"RelativeToolTip": "ProducerConsumerProblem.c",
|
||||
"ViewState": "AQIAACwAAAAAAAAAAAAAADQAAAAmAAAA",
|
||||
"ViewState": "AQIAACoAAAAAAAAAAAAAwDIAAAAXAAAA",
|
||||
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000423|",
|
||||
"WhenOpened": "2024-03-21T03:02:20.673Z",
|
||||
"EditorCaption": ""
|
||||
@@ -54,8 +54,7 @@
|
||||
"RelativeToolTip": "queue\\queue.h",
|
||||
"ViewState": "AQIAAAwAAAAAAAAAAAAAACIAAAAGAAAA",
|
||||
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000680|",
|
||||
"WhenOpened": "2024-03-21T02:59:47.406Z",
|
||||
"EditorCaption": ""
|
||||
"WhenOpened": "2024-03-21T02:59:47.406Z"
|
||||
},
|
||||
{
|
||||
"$type": "Document",
|
||||
@@ -67,8 +66,7 @@
|
||||
"RelativeToolTip": "queue\\queue.c",
|
||||
"ViewState": "AQIAABIAAAAAAAAAAAAAAAAAAAALAAAA",
|
||||
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000423|",
|
||||
"WhenOpened": "2024-03-21T02:59:19.431Z",
|
||||
"EditorCaption": ""
|
||||
"WhenOpened": "2024-03-21T02:59:19.431Z"
|
||||
},
|
||||
{
|
||||
"$type": "Document",
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
1746076351 E:\MultiThreading_Part_A\ProducerConsumerProblem\CMakeLists.txt
|
||||
656492842 E:\MultiThreading_Part_A\ProducerConsumerProblem\CMakePresets.json
|
||||
266116938 E:\MultiThreading_Part_A\ProducerConsumerProblem\ProducerConsumerProblem.c
|
||||
627020441 E:\MultiThreading_Part_A\ProducerConsumerProblem\ProducerConsumerProblem.c
|
||||
656638558 E:\MultiThreading_Part_A\ProducerConsumerProblem\ProducerConsumerProblem.h
|
||||
724450421 E:\MultiThreading_Part_A\ProducerConsumerProblem\
|
||||
-515039357 E:\MultiThreading_Part_A\ProducerConsumerProblem\
|
||||
-567993927 E:\MultiThreading_Part_A\ProducerConsumerProblem\queue\queue.c
|
||||
-683853765 E:\MultiThreading_Part_A\ProducerConsumerProblem\queue\queue.h
|
||||
1584755146 E:\MultiThreading_Part_A\ProducerConsumerProblem\queue\
|
||||
|
||||
Binary file not shown.
@@ -6,8 +6,10 @@ struct Queue_t* reso;
|
||||
|
||||
static const char* prod1 = "TP1";
|
||||
static const char* prod2 = "TP2";
|
||||
static const char* prod3 = "TP3";
|
||||
static const char* cons1 = "TC1";
|
||||
static const char* cons2 = "TC2";
|
||||
static const char* cons3 = "TC3";
|
||||
|
||||
void*
|
||||
producer_fn_callback(void* arg) {
|
||||
@@ -118,20 +120,34 @@ main(int argv, char* argc[]) {
|
||||
|
||||
pthread_t pt1;
|
||||
pthread_t pt2;
|
||||
pthread_t pt3;
|
||||
pthread_t ct1;
|
||||
pthread_t ct2;
|
||||
pthread_t ct3;
|
||||
|
||||
reso = initQ();
|
||||
|
||||
create_thread(&pt1,producer_fn_callback,prod1);
|
||||
create_thread(&pt2,producer_fn_callback,prod2);
|
||||
create_thread(&pt3, producer_fn_callback, prod3);
|
||||
create_thread(&ct1,consumer_fn_callback,cons1);
|
||||
create_thread(&ct2,consumer_fn_callback,cons2);
|
||||
create_thread(&ct3, consumer_fn_callback, cons3);
|
||||
|
||||
pthread_join(pt1, NULL);
|
||||
pthread_join(pt2, NULL);
|
||||
pthread_join(pt3, NULL);
|
||||
pthread_join(ct1, NULL);
|
||||
pthread_join(ct2, NULL);
|
||||
pthread_join(ct3, NULL);
|
||||
|
||||
|
||||
if (!is_queue_empty(reso)) {
|
||||
printf("Queue is not Drained completely. Program didn't execute properly\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
printf("Size of Queue: %d\n", Q_COUNT(reso));
|
||||
|
||||
printf("Program finished\n");
|
||||
pthread_exit(0);
|
||||
|
||||
Reference in New Issue
Block a user