Synchronisation

Race condition
A situation where multiple threads may manipulate data in such a way that the outcome depends on the execution order.
Critical Section
A section of code that manipulates shared data.
Mutual Exclusion
Making sure that only one thread can be executing in a critical section at once.
Deadlock
When two or more processes are waiting for something that can only be provided by one of the waiting processes.

Semaphores

  • Two operations on a shared value:

    P(s)
    while (s <= 0) {}
    s--;
    V(s)
    s++;
  • Don’t busy wait; give up the cpu.

Java

wait()
Give up the lock, and yield to another thread, waiting for something to call notify.
notify()
Yield to a waiting thread.
notifyAll()
Wake up all waiting threads.

Table Of Contents

Previous topic

Scheduling

Next topic

Memory

This Page