#Sales Offer!| Get upto 25% Off:

The InterlockedExchange function was described in Section 2.3. It has two parameters and behaves like the following atomic function:

LONG InterlockedExchange (LONG* target, LONG newValue) {
LONG temp = *target; *target = newValue; return temp;
}

The following is an implementation of a countingSemaphore using InterlockedExchange():

Statements

while (InterlockedExchange(const_cast(&mutex),true))

 

{Sleep(0);};

and

mutex = false;

are used to enforce mutual exclusion for permits. In the P() operation,

the statement

while (InterlockedExchange(const_cast(&block),true))

 

{Sleep(0);}

is used to delay threads that are waiting to be awakened by V() operations. In the V() operation, the statement

while (!block) {Sleep(0);};

is used to make sure that block is set to false only when it is true. The initial value of block is true. Block is set to false in order to awaken a delayed thread. After block is set to false, it remains false until a delayed thread executes InterlockedExchange(const cast<>∗> (&block),true). (Then the delayed thread becomes awakened.) If block is false when V() is executed, the previous V() operation has not yet awakened a delayed thread.

(a) Show that the deletion of while (!block) {Sleep(0);} in V() can create an error.

Found something interesting ?

• On-time delivery guarantee
• PhD-level professional writers
• Free Plagiarism Report

• 100% money-back guarantee
• Absolute Privacy & Confidentiality
• High Quality custom-written papers

Related Model Questions

Feel free to peruse our college and university model questions. If any our our assignment tasks interests you, click to place your order. Every paper is written by our professional essay writers from scratch to avoid plagiarism. We guarantee highest quality of work besides delivering your paper on time.

Grab your Discount!

25% Coupon Code: SAVE25
get 25% !!