Algorithm of bakery

The Algorithme of bakery is an algorithm of mutual exclusion invented by Leslie Lamport. It uses Attente activates to guarantee the mutual exclusion.

The algorithm

To guarantee mutual exclusion with NR tasks, one has two tables of dimension NR (named thereafter CHOICE and METER). The algorithm is in three parts: initialization, the entry in critical section and the exit of the critical section.

Initialization

To initialize all the box of METER with -1. To initialize all the box of CHOICE to 0.

Entry in critical section

I indicates the number of the thread wishing to enter in critical section.

CHOICE = 1 METER = 1 + max (METER) CHOICE = 0 J = I + 1 TANTQUE J <> I TO MAKE TANTQUE CHOICE <> 1 TO MAKE nothing FINE TANTQUE IF METER > METER AND METER <> -1 THEN TANTQUE METER <> -1 TO MAKE nothing FINE TANTQUE END IF J = (J + 1) modulo NR FINE TANTQUE

Exit of the critical section

I indicates the number of the thread wishing to leave the critical section.

COMPTEUR=-1

See too

  • Attente activates

Random links:Vendeuvre-on-Barse | Randy Schooley | Michelle Burke | It was once Walt Disney | Raquella Berto-Anirul | Histoire_de_sel_iodisé