Question
#include #include #include #include #include pthread_t threadid[4]; struct binop { int a; int b; }BinOp; pthread_mutex_t lock; void* add(void *arg) { unsigned long i =
#include #include #include #include #include pthread_t threadid[4]; struct binop { int a; int b; }BinOp; pthread_mutex_t lock; void* add(void *arg) { unsigned long i = 0; printf("Thread 1 has started but waiting "); pthread_mutex_lock(&lock); printf("Thread 1 has started running "); for(i = 0; i < (0xFFFFFFFF); i++); printf("Addition : %d ", BinOp.a + BinOp.b); pthread_mutex_unlock(&lock); return NULL; } void* sub(void *arg) { unsigned long i = 0; printf("Thread 2 has started but waiting "); pthread_mutex_lock(&lock); printf("Thread 2 has started running "); for(i = 0; i < (0xFFFFFFFF); i++); printf("Substraction : %d ", BinOp.a - BinOp.b); pthread_mutex_unlock(&lock); return NULL; } void* mul(void *arg) { unsigned long i = 0; printf("Thread 3 has started but waiting "); pthread_mutex_lock(&lock); printf("Thread 3 has started running "); for(i = 0; i < (0xFFFFFFFF); i++); printf("Multiplication : %d ", BinOp.a * BinOp.b); pthread_mutex_unlock(&lock); return NULL; } void* division(void *arg) { unsigned long i = 0; printf("Thread 4 has started but waiting "); pthread_mutex_lock(&lock); printf("Thread 4 has started running "); for(i = 0; i < (0xFFFFFFFF); i++); printf("Division : %d ", BinOp.a / BinOp.b); pthread_mutex_unlock(&lock); return NULL; } int main(void) { int i = 0; int error; BinOp.a = 4; BinOp.b = 3; if (pthread_mutex_init(&lock, NULL) != 0) { printf(" mutex init has failed "); return 1; } error = pthread_create(&(threadid[0]), NULL, &add, NULL); if (error != 0) printf(" Thread can't be created : [%s]", strerror(error)); error = pthread_create(&(threadid[1]), NULL, , NULL); if (error != 0) printf(" Thread can't be created : [%s]", strerror(error)); error = pthread_create(&(threadid[2]), NULL, &mul, NULL); if (error != 0) printf(" Thread can't be created : [%s]", strerror(error)); error = pthread_create(&(threadid[3]), NULL, &division, NULL); if (error != 0) printf(" Thread can't be created : [%s]", strerror(error)); pthread_join(threadid[0], NULL); pthread_join(threadid[1], NULL); pthread_join(threadid[2], NULL); pthread_join(threadid[3], NULL); pthread_mutex_destroy(&lock); return 0; can i have the design for the above project..?
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started