Which two actions should you perform?

You design an application that processes large amount of user data. The application consists of multiple producer and consumer threads. All threads share a single task queue. You write the following pseudocode. (Line numbers are included for reference only.)

01 task_available = 0; // shared variable
02 Producer_Thread:
03 inserted = 0 // private
04 while (!done()) {
05 inserted = 0;
06 create_task(my_task); //private
07 while (inserted == 0) {
08 if (task_available == 0) {
09 insert_into_queue(my_task);
10 task_available = 1;
11 inserted = 1;
12 }
13 }
14 }
15 end Producer_Thread
16 Consumer_Thread:
17 extracted = 0; // private
18 while (!done()) {
19 extracted = 0;
20 while (extracted == 0) {
21 if (task_available == 1) {
22 extract_from_queue(my_task);
23 task_available = 0;
24 extracted = 1;
25 }
26 }
27 }
28 process_task(my_task);
29 end Consumer_Thread

You need to ensure that multiple instances of the producer and consumer threads can run without deadlocks.
Which two actions should you perform? (Each correct answer presents part of the solution.
Choose two.)

You design an application that processes large amount of user data. The application consists of multiple producer and consumer threads. All threads share a single task queue. You write the following pseudocode. (Line numbers are included for reference only.)

01 task_available = 0; // shared variable
02 Producer_Thread:
03 inserted = 0 // private
04 while (!done()) {
05 inserted = 0;
06 create_task(my_task); //private
07 while (inserted == 0) {
08 if (task_available == 0) {
09 insert_into_queue(my_task);
10 task_available = 1;
11 inserted = 1;
12 }
13 }
14 }
15 end Producer_Thread
16 Consumer_Thread:
17 extracted = 0; // private
18 while (!done()) {
19 extracted = 0;
20 while (extracted == 0) {
21 if (task_available == 1) {
22 extract_from_queue(my_task);
23 task_available = 0;
24 extracted = 1;
25 }
26 }
27 }
28 process_task(my_task);
29 end Consumer_Thread

You need to ensure that multiple instances of the producer and consumer threads can run without deadlocks.
Which two actions should you perform? (Each correct answer presents part of the solution.
Choose two.)

A.
Create a critical section that includes lines 07 through 12.

B.
Create a critical section that includes lines 03 through 13.

C.
Create a critical section that includes lines 20 through 25.

D.
Create a critical section that includes lines 17 through 26.



Leave a Reply 0

Your email address will not be published. Required fields are marked *