|
|
|
|
|
by mrkeen
2062 days ago
|
|
I'd say provide concurrency primitives to disallow direct access to shared mutable state. You still do the reads and the writes, but you let the system take and release locks for you. Let's say you wanted to turn a list into a bounded list of 4 elements. Race-condition insert: if (sz < 4) {
list.insert(x);
sz++;
}
Safe insert: atomically {
if (sz < 4) {
list.insert(x);
sz++;
}
}
So atomically organises the locking/unlocking/rollback for you such that a fifth element will not be inserted. |
|