mirror of
https://github.com/jackyzha0/quartz.git
synced 2025-12-27 14:54:05 -06:00
vault backup: 2022-10-30 14:55:53
This commit is contained in:
parent
663a67d6cc
commit
9c9fffafc5
@ -53,3 +53,24 @@ CONSUMER: repeat
|
|||||||
counter is a shared variable - causes a data race problem
|
counter is a shared variable - causes a data race problem
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
|
# critical sections
|
||||||
|
guarantee that certain sections of coopeating processes are not interleaved to avoid data race problem
|
||||||
|
|
||||||
|
only one process can execute critical section at a time
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
but there is a data race problem for locking the processes!
|
||||||
|
|
||||||
|
# hardware locking
|
||||||
|
disalow interrupts while a shared variable is being modified. only works for one CPU
|
||||||
|
|
||||||
|
modern computers have special **atomic instructions**
|
||||||
|
- CompareAndSwap
|
||||||
|
- testAndSet
|
||||||
|
|
||||||
|
`CAS(0, a, n)`: If the value at address a is o, write the value n to address a and then return true; Otherwise, return false, where o and n are integers, and a is the address of a memory location.
|
||||||
|
|
||||||
|
# CAS based LOCK function
|
||||||
|

|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user