News for hackers. Stuff that matters.
Re:Inter-window messaging using localStorage by tiles on Saturday March 09, 2013 @12:36PM (#5349001)
If you want to use localStorage atomically, I found this writeup and code on a LockableStorage interface to be very thorough: http://balpha.de/2012/03/javascript-concurrency-and-locking-...
Re:Inter-window messaging using localStorage by hobohacker on Saturday March 09, 2013 @02:36PM (#5349341)
It depends on what you mean by atomic. Please refer to http://www.chromium.org/developers/design-documents/indexedd... where Chromium devs state: """ LocalStorage is inherently racy or a parallelism disaster, depending on whether or not you're willing to implement the "storage mutex" described in the spec. Chromium has decided not to implement it. WebKit itself is single thread/process (i.e. no parallelism period). """

Note that the way Chromium implements localStorage, it uses a disk backing store of sqlite, a caching layer (a std::map) in the browser process, and a caching layer (also a std::map) in the renderer processes (where WebKit runs, and may handle 1-X tabs per process). Changes are propagated via IPC, but as the API does not provide any locking guarantees beyond the optional storage mutex, which Chromium does not implement, there are obviously race conditions.

This probably explains the issues the author of that post encountered with Chrome.

Re:Inter-window messaging using localStorage by khuey on Saturday March 09, 2013 @02:49PM (#5349386)
The storage mutex is still technically in the spec, but no browser is going to implement it.
Re:Inter-window messaging using localStorage by bensummers on Saturday March 09, 2013 @12:46PM (#5349038)
That's rather cool. And nice to see a use of the Lamport algorithm in a browser. :-)