555 views
0 votes
0 votes
Consider how to implement a mutex lock using an atomic hardware instruction. Assume that the following structure defining the mutex
lock is available:
typedef struct {
int available;
} lock;
(available == 0) indicates that the lock is available, and a value of 1 indicates that the lock is unavailable. Using this struct, illustrate how the following functions can be implemented using the test and set() and compare and swap() instructions:
• $void acquire(lock *mutex)$
•$ void release(lock *mutex)$
Be sure to include any initialization that may be necessary.

Please log in or register to answer this question.

Related questions

0 votes
0 votes
0 answers
1
akash.dinkar12 asked Mar 20, 2019
267 views
Describe how the compare_and_swap() instruction can be used to provide mutual exclusion that satisfies the bounded-waiting requirement.
0 votes
0 votes
0 answers
2
akash.dinkar12 asked Mar 20, 2019
585 views
Describe two kernel data structures in which race conditions are possible.Be sure to include a description of how a race condition can occur.
0 votes
0 votes
0 answers
3
akash.dinkar12 asked Mar 20, 2019
357 views
The Linux kernel has a policy that a process cannot hold a spin lock while attempting to acquire a semaphore. Explain why this policy is in place.
0 votes
0 votes
0 answers
4