[go: up one dir, main page]

0% found this document useful (0 votes)
52 views1 page

Operating System Design, Fall 2021: Lab Activity Guidance

The document provides guidance for a lab activity on understanding synchronization mechanisms in an operating system. It instructs students to examine existing spinlock and mutex code to understand how they work. It also tasks students with implementing semaphore functionality by defining necessary data structures and functions for initialization, acquiring, and releasing a semaphore. Comparing and contrasting spinlocks, mutexes, and semaphores is also included.

Uploaded by

Feli Herman
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
52 views1 page

Operating System Design, Fall 2021: Lab Activity Guidance

The document provides guidance for a lab activity on understanding synchronization mechanisms in an operating system. It instructs students to examine existing spinlock and mutex code to understand how they work. It also tasks students with implementing semaphore functionality by defining necessary data structures and functions for initialization, acquiring, and releasing a semaphore. Comparing and contrasting spinlocks, mutexes, and semaphores is also included.

Uploaded by

Feli Herman
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

 1 Felician-Nicu Herman

Operating System Design, Fall 2021 

 Home  Dashboard  Events  My courses  This course  Hide blocks  Standard view

  My courses  OSD (2021/2022 - A. Coleșa)  18 October - 24 October  Lab activity guidance

Lab activity guidance  Navigation


Preparations:   Dashboard
 Site home
We will not be running tests today and we simply want to boot HAL9000, before starting work make sure you run the RemoveAllTests project.
Then after each time you build HAL9000, start manually the VM from VMWare workstation.  Site pages

Lab Activity:  My courses


 PRC/CND (2021/2022 - E. Cebuc)
Understanding existing synchronization mechanisms
1. Take a look at SpinlockAcquire():  RC/CN (2020/2021 - B. Iancu, V. Dădârlat)
  a. Why does it have an additional parameter beside the lock?
  b. Find the line where the lock is actually taken, what kind of operation is performed? Is this necessary if interrupts are disabled?  CAN / ADC (2019/2020 - B. Iancu)
  c. What is the signi cance of the Holder and FunctionWhichTookLock elds?
 SO.2020.Seria2
 OSD (2021/2022 - A. Coleșa)
2. Take a look at SpinlockRelease():
  a. What is the deal with the asserts at the beginning of the function? What do they test?  Participants
  b. Find the line where the lock is released, what kind of operation is performed? Is this necessary if interrupts are disabled?
  c. How is the additional parameter OldIntrState used?
 Badges
 Competencies
3. Take a look at MutexAcquire():  Grades
  a. explain the code between lines 39-45 (executed if (pCurrentThread == Mutex->Holder) is TRUE).
  b. why is another lock acquired in this function? (what's the deal with LockAcquire(&Mutex->MutexLock)?)  General
  c. Explain the while loop? Why is it needed? Why doesn't the thread which wakes up simply take the mutex?  27 September - 3 October
 4 October - 10 October
4. Take a look at MutexRelease():
  a. Why is the holder of the mutex set as the next thread? couldn't it simply be set to NULL? a single thread is unblocked anyway, is there any di erent if the holder would be set to NULL?  11 October - 17 October
 18 October - 24 October
5. When should spinlock be used in our code and when should mutexes be used? Compare and contrast the two synchronization mechanisms. Lab activity guidance

Implementing semaphores Lab 4 git di

1. Implement semaphore functionality by implementing the following functions: Learning part quiz

Learning part quiz


typedef struct _SEMAPHORE
{ Send DESIGN document for the "Threads" module
DWORD Value;
(onl...
// ... add more fields here ...  25 October - 31 October
} SEMAPHORE, *PSEMAPHORE;
 1 November - 7 November
void
 8 November - 14 November
SemaphoreInit(
OUT PSEMAPHORE Semaphore,  15 November - 21 November
IN DWORD InitialValue
);  22 November - 28 November
 29 November - 5 December
void
SemaphoreDown(  6 December - 12 December
INOUT PSEMAPHORE Semaphore,
IN DWORD Value  13 December - 19 December
);  20 December - 26 December

void  27 December - 2 January


SemaphoreUp(
 3 January - 9 January
INOUT PSEMAPHORE Semaphore,
IN DWORD Value  10 January - 16 January
);
    Examinations
2. First, implement semaphores using busy waiting. When should these semaphores be used? What are their advantages/disadvantages?
 PSO (2021/2022 - A. Coleșa)
3. Modify the busy waiting implementation using the block/unblock mechanism. When should these semaphores be used? What are their advantages/disadvantages?
4. Add a new command "/testsemas". The main thread should create a semaphore with an InitialValue of 0 and then send an IPI to each processor except himself (SmpSendGenericIpi()) to execute a  LFT (2020/2021, A. Marginean, seria 2)
function which increments the semaphore value by 1. The main thread should then down the semaphore with the value being equal to the number of active CPUs in the system - 1.
Implementing conditional variables  SI (2020/2021, R. R. Slavescu)
 Consiliere Studenti 2021-2022
typedef struct _CONDITIONAL_VARIABLE
{  PF seria B (2020/2021 - R.R. Slavescu)
LIST_ENTRY WaiterList;
} CONDITIONAL_VARIABLE, *PCONDITIONAL_VARIABLE; More...

// Initializes condition variable CondVariable. A condition variable


// allows one piece of code to signal a condition and cooperating
// code to receive the signal and act upon it.
void
CondVariableInit(
OUT PCONDITIONAL_VARIABLE CondVariable
);

// Atomically releases Lock and waits for CondVariable to be signaled by


// some other piece of code. After CondVariable is signaled, Lock is
// reacquired before returning. Lock must be held before calling
// this function.
//
// The monitor implemented by this function is "Mesa" style, not
// "Hoare" style, that is, sending and receiving a signal are not
// an atomic operation. Thus, typically the caller must recheck
// the condition after the wait completes and, if necessary, wait
// again.
//
// A given condition variable is associated with only a single
// lock, but one lock may be associated with any number of
// condition variables. That is, there is a one-to-many mapping
// from locks to condition variables.
//
// This function may sleep, so it must not be called within an
// interrupt handler. This function may be called with
// interrupts disabled, but interrupts will be turned back on if
// we need to sleep. */
void
CondVariableWait(
INOUT PCONDITIONAL_VARIABLE CondVariable,
INOUT PMUTEX Lock
);

// If any threads are waiting on CondVariable (protected by Lock), then


// this function signals one of them to wake up from its wait.
// Lock must be held before calling this function.
//
// An interrupt handler cannot acquire a lock, so it does not
// make sense to try to signal a condition variable within an
// interrupt handler.
void
CondVariableSignal(
INOUT PCONDITIONAL_VARIABLE CondVariable,
INOUT PMUTEX Lock
);

// Wakes up all threads, if any, waiting on CondVariable (protected by


// Lock). Lock must be held before calling this function.
//
// An interrupt handler cannot acquire a lock, so it does not
// make sense to try to signal a condition variable within an
// interrupt handler.
void
CondVariableBroadcast(
INOUT PCONDITIONAL_VARIABLE CondVariable,
INOUT PMUTEX Lock
);
  
1. Can you implement conditional variables using busy waiting? (hint: look at the type of lock you're using)
2. Implement a similar command as for semaphores ("/testcondvars") to test your conditional variable implementation.
Last modi ed: Sunday, 16 October 2016, 3:54 PM

PREVIOUS ACTIVITY NEXT ACTIVITY


 Send DESIGN document for the "Threads" module (only students attending project 
Lab 4 git di
classes in ODD WEEKS)

Jump to...

Get the mobile app

You might also like