sahaitong814
28.06.2020 •
Computers and Technology
Write all possible outputs of the following C program. Separate different possibilities clearly. Assume there will be no mutex or semaphore initialization, thread creation or joining failures. If you believe there is only one possible output, you just need to write that output. #include #include char arr [2]={'a','b']; int mark=0, size=0; pthread_mutex_t ml = PTHREAD_MUTEX_INITIALIZER; { void swap (int start, int end) { int i, j; for (i=start, j=mark;i<=end; i++) pthread_mutex_lock (&ml); arr[0]=arr[O] + (j82); arr[1]=arr[1]+(j82); pthread_mutex_unlock (&ml); } } void *fun (void *arg) { swap (mark, mark+size-1); mark=mark+size; } int main(int argc, char *argv[]) { int num_threads=2, i, x; size=14/num_threads; pthread_t thread[num_threads]; for( i = 0; i < num_threads; i++) x = pthread_create(&thread[i], NULL, fun, NULL); for( i = 0; i < num_threads; i++) pthread_join(thread[i], NULL); for(i=0;i<2;i++) printf("%c", arr[i]); return 0;
Solved
Show answers
More tips
- H Health and Medicine What to Eat to Lose Weight?...
- S Society and Politics Will Japan become Russia s Military Enemy?...
- P Philosophy Is Everything We Strive for Eventually Achieved and Destroyed?...
- S Society and Politics Understanding Politics and Its Role in the Development of Civilization...
- P Philosophy Why Did God Create Man and Place Him in Obscurity?...
- S Society and Politics Skoptsy: Who They Are and How They Perform Castration?...
- O Other Childhood Fears: What Many of Us Experienced...
- P Philosophy What is Something for you?...
- H Health and Medicine Why Do Humans Have One Heart?...
- P Philosophy Unbelievable stories of encounters with otherworldly forces...
Answers on questions: Computers and Technology
- M Mathematics Which expression can be used to find the value of the expression below? 6.1 – 5.4 - (-7.7) A 6.1 - 5.4 - 7.7 B 6.1 + 5.4 + (-7.7) Mikayla С 6.1 + 7.7 - 5.4 Vair D 6.1 + 7.7 + 5.4 N...
- L Law Johnson, a fraud defendant, is being tried in a U.S. criminal case. Blue, a Certified Fraud Examiner (CFE), is a key fact witness in Johnson s trial. At what point does Johnson have...
- B Biology What do consumers,producers, and decomposers have in common...
- H Health Thực đơn ăn uống tốt cho cơ bắp là gì ?...
- M Mathematics I need the answer please...
Ответ:
id
Explanation: