Tutorial 1 OS 2025
Tutorial 1 OS 2025
Exercise 1 :
1. What is a race condition? Give an example.
2. What is a critical region? How are they relate to controlling access to shared resources?
3. What are the three requirements of any solution to the critical sections problem? Why are the
requirements needed?
4. Why is turn passing a poor solution to the critical sections problem?
5. What is the producer consumer problem? Give an example of its occurrence in operating systems.
6. A semaphore is a blocking synchronization primitive. Describe how they work with the
aid of pseudo-code. You can assume the existence of a thread_block() and a thread_wakeup()
function.
7. Interrupt disabling and enabling is a common approach to implementing mutual exclusion, what
are its advantages and disadvantages?
8. Locks prevent the OS scheduler from performing a context switch during a critical section.
9. Peterson’s algorithm uses the atomic fetch-and-add instruction to provide mutual exclusion for
two threads.
10. A lock implementation should block instead of spin if it will always be used only on a
uniprocessor.
11. What is a test-and-set instruction? How can it be used to implement mutual exclusion? Consider
using a fragment of psuedo-assembly language aid you explanation.
enter_region:
tsl register, lock
cmp register, #0
b enter_region ; if non-zero the lock was set, so loop!
b critical_region ; else, the lock was 0, so get in there
leave_region:
mov lock, #0 ; store a 0 in the lock
b caller
12. What are monitors and condition variables?
13. Describe how to implement a lock using semaphores
14. Explain semaphores and write a short note on it.
15. Explain de producer consumer problem and how you can solve the problem using semaphore.
16. Explain the dinner philosopher and how you can solve the problem using semaphore.
17. Using a simple system call as an example (e.g. getpid, or uptime), describe what is generally
involved in providing the result, from the point of calling the function in the C library to the
point where that function returns.
18. With producer/consumer relationships and a finite-sized circular shared buffer, producing threads
must wait until there is an empty element of the buffer.
19. What is the difference between Job and Process?
20. What is the relationship between threads and processes?
21. What is a process? What are attributes of a process?
22. What is the function of the ready queue?
1 10
2 29
3 3
4 7
5 12
Problem 3:
Given that the following processes arrive for execution at the times indicated, each process will run for
the amount of time listed. In answering the questions, use non-preemptive scheduling and base all
decisions on the information you have at the time the decision is made.
1. Draw Gantt chart for these processes with the First Come First Served (FCFS) and Shortest
Job First (SJF) scheduling algorithms.
2. Calculate the average waiting time for each of the above algorithms.
3. Which one is more efficient than the other one?