There are several ways that the operating system may achieve mutual exclusion of its critical regions within processes. For one reason or another, though, none of the following mechanisms are generally suitable for use in user-level code.
The first two are 'hardware' solutions; the second two are 'software' solutions:
All the techniques described above are rather antisocial to other processes: the last three depend on busywaiting in order to work; the first switches off task-switching. This makes them impractical when the critical sections are large.
In practice, the above techniques are used within the kernel for...