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);
}
var object = new Object() {
volatile int x;
};
new Thread(() -> {
synchronized (object) {
int x = object.x;
}
}).start();
synchronized (object) {
object.x = 123;
}
class Example<T> {
volatile T x;
Object m = new Object();
void set(T x) {
synchronized (m) {
this.x = x;
}
}
T get() {
synchronized (m) {
return 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);