Question: Figure is a listing of code intended for use on the eCos kernel. a. Explain the operation of the code. Assume thread B begins execution

Figure is a listing of code intended for use on the eCos kernel.
Figure is a listing of code intended for use on

a. Explain the operation of the code. Assume thread B begins execution first and thread A begins to execute after some event occurs.
b. What would happen if the mutex unlock and wait code execution in the call to cyg_cond_wait, on line 30, were not atomic?
c. Why is the while loop on line 26 needed?

1 unsigned char buffer_empty true; mutex t mut cond var; 3 cyg cond-t cond_var; 5 void thread af cyg_ addrword t index ) 7 while 1 run this thread forever // acquire data into the buffer... 10 // there is data in the buffer now 12 13 14 15 16 17 18 19 20 21 22 void thread b cyg addrword t index ) 23 24 while 1 /run this thread forever 25 26 27 28 29 3 0 31 32 buffer-empty false; cyg mutex lock f &mut cond var cyg cond signal cond var ) .-mutex-unlock( &mut-cond-var ); , mutex-lock ( &mut. Cond-var while ( buffer_empty true) cyg-cond-wait( &cond-var ); ); // get the buffer data. 34 35 36 37 38 39 4 0 // set flag to indicate the data in the buffer has been processed buffer empty truei cyg mutex unlock ( &mut cond var // process the data in the buffer 4 2 43

Step by Step Solution

3.42 Rating (168 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

a This listing is an example using a condition variable Thread A is acquiring data that are processe... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Document Format (1 attachment)

Word file Icon

451-C-S-D-B-O-S (222).docx

120 KBs Word File

Students Have Also Explored These Related Operating System Questions!