Be concise.
Be useful.
All contributions dictatorially edited by webmasters to match personal tastes.
Please do not paste any copyright violating material.
Please try to avoid dependencies to third-party libraries and frameworks.
(def x (atom 0))
(def f inc)
(swap! x f)
private readonly object m_Sync = new object();
lock(m_Sync)
{
x = f(x);
}
lock (x) {
x = f(x);
}
synchronized x = f(x);
x = f(x);
x = f(x)
integer, dimension[*] :: x
critical
x = f(x)
end critical
let x = f(x)
synchronized(lock){
x = f(x);
}
volatile T x;
class Example<T> {
T x;
Object lock = new Object();
T read() {
synchronized (lock) {
return x;
}
}
void write(T x) {
synchronized (lock) {
this.x = x;
}
}
}
$mutex = Mutex::create();
Mutex::lock($mutex);
$x = f($x);
Mutex::unlock($mutex);
Mutex::destroy($mutex);
let mut x = x.lock().unwrap();
*x = f(x);