Logo

Programming-Idioms

History of Idiom 33 > diff from v20 to v21

Edit summary for version 21 by :
New PHP implementation by user [AgillaDev]

Version 20

2016-03-20, 23:33:23

Version 21

2016-03-29, 13:42:52

Idiom #33 Atomically read and update variable

Assign variable x the new value f(x), making sure that no other thread may modify x between the read and the write.

Idiom #33 Atomically read and update variable

Assign variable x the new value f(x), making sure that no other thread may modify x between the read and the write.

Code
$mutex = Mutex::create();
Mutex::lock($mutex);
$x = f($x);
Mutex::unlock($mutex);
Mutex::destroy($mutex);
Doc URL
http://php.net/manual/en/class.mutex.php