Created by Aidas Klimas
Any indivisible operation operating systems can do atomically, making them useful as building blocks for thread-safe and multi-process-safe programs without mutexes or read/write locks
mv file-path file-path-2 # move file once
mkdir folder-path # create file once
mv file-path file-path-2 # FAIL
mv file-path file-path-2 # SUCCESS
Full list https://rcrowley.org/2010/01/06/things-unix-can-do-atomically.html
CREATE TABLE dogs (
id INT PRIMARY KEY, name varchar(255)
);
INSERT INTO dogs (id, name) VALUES
(1, 'Gile'), (2, 'Pukis'); -- 2 rows affected
INSERT INTO dogs (id, name) VALUES
(1, 'Gile'), (2, 'Pukis'); -- 0 rows affected
update dogs set name = 'labas' where id = 1; -- 1 rows affected
update dogs set name = 'labas' where id = 1; -- 0 rows affected
delete from dogs where id = 1; -- 1 rows affected
delete from dogs where id = 1; -- 0 rows affected
Cache::add('cache-key', 'value'); // true
Cache::add('cache-key', 'value 2'); // false
Cache::put('cache-key', 'value') // always true, not very useful
Cache::forget('cache-key');
Cache::increment('cache-key');
VS NON ATOMIC
$value = Cache::get('cache-key');
Cache::put('cache-key', $value + 1)
Go to
https://gitlab.com/ekomlita/workshop/atomic-operations-workshop
clone and follow readme
Get slides from klimas.lt/slides