Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question bellow mentioned are example of threads in c using pthread, task is to convert this program in Python and OpenMP. #include #include #include pthread_mutex_t

Question bellow mentioned are example of threads in c using pthread, task is to convert this program in Python and OpenMP.image text in transcribed

#include #include #include pthread_mutex_t count_mutex = PTHREAD_MUTEX_INITIALIZER: pthread mutext condition_mutex = PTHREAD_MUTEX INITIALIZER: pthread_cond_t condition_cond = PTHREAD_COND_INITIALIZER; void *function Count10: void *functionCount20: int count = 0; #define COUNT_DONE 10 #define COUNT_HALTI 3 #define COUNT_HALT26 main { pthread_t thread1, thread2: pthread_create(&thread1, NULL, &functionCount1, NULL): pthread_createl &thread2, NULL, &functionCount2, NULL). pthread_join(thread1,NULL); pthread_join(thread2, NULL); exit(0); } void *functionCount() { for(:) { pthread_mutex_lock( &condition_mutex); while( count >= COUNT_HALT1 && count = COUNT_DONE) return(NULL); } } void *functionCount20) { for(:) { pthread_mutex_lock( &condition_mutex): { pthread_cond_signal( &condition_cond); } pthread_mutex_unlock( &condition_mutex); pthread_mutex_lock( &count_mutex); count++; printf("Counter value functionCount2: %d ",count): pthread_mutex_unlock( &count_mutex): if(count >= COUNT_DONE) return(NULL); } ) #include #include #include pthread_mutex_t count_mutex = PTHREAD_MUTEX_INITIALIZER: pthread mutext condition_mutex = PTHREAD_MUTEX INITIALIZER: pthread_cond_t condition_cond = PTHREAD_COND_INITIALIZER; void *function Count10: void *functionCount20: int count = 0; #define COUNT_DONE 10 #define COUNT_HALTI 3 #define COUNT_HALT26 main { pthread_t thread1, thread2: pthread_create(&thread1, NULL, &functionCount1, NULL): pthread_createl &thread2, NULL, &functionCount2, NULL). pthread_join(thread1,NULL); pthread_join(thread2, NULL); exit(0); } void *functionCount() { for(:) { pthread_mutex_lock( &condition_mutex); while( count >= COUNT_HALT1 && count = COUNT_DONE) return(NULL); } } void *functionCount20) { for(:) { pthread_mutex_lock( &condition_mutex): { pthread_cond_signal( &condition_cond); } pthread_mutex_unlock( &condition_mutex); pthread_mutex_lock( &count_mutex); count++; printf("Counter value functionCount2: %d ",count): pthread_mutex_unlock( &count_mutex): if(count >= COUNT_DONE) return(NULL); } )

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle 11G SQL

Authors: Joan Casteel

2nd Edition

1133947360, 978-1133947363

More Books

Students also viewed these Databases questions

Question

=+1. Give the balance sheet to Melissa.

Answered: 1 week ago

Question

Please make it fast 6 6 1 .

Answered: 1 week ago

Question

What are the stages of project management? Write it in items.

Answered: 1 week ago

Question

' Which areas depend on inputs from you to get their work donel>

Answered: 1 week ago

Question

What do we do that frustrates each other?

Answered: 1 week ago