What local storage in html5 can I use safely in the browser ui thread and the web worker thread
Asked Answered
B

1

6

I've been trying to use web sql database api in webkit based browsers. I have been using the async api in the main ui thread and a web worker. Both threads access the same database (which as you know is sqlite underthehood)

Everything behaves fine but occassionally transactions are lost or one transaction fails and it seems to be a timing/race condition. It appears access to the underlying sqlite database is not thread-safe.

A bit more background. My web worker is simply executing a query against a table that may have a record inserted into it from the main ui thread.

I am wondering if it is actually documented somewhere what local/web storage can be accessed safely from both the ui thread and the web worker thread? I've read somewhere that the indexeddb api is thread safe but that does not help me right now since browser support for it is poor/non-existent for the browsers I am targeting (at least I think so - I get my information from http://caniuse.com )

Any insights would be gratefully received

Bombardon answered 15/2, 2012 at 14:43 Comment(3)
I didn't even know that its possible to access local storage in worker thread? See #6179659Inhospitable
Yes you maybe right. I possibly made the incorrect assumption since WEB SQL databases are accessible from the worker thread. Unfortunately they do not seem to be thread safe when you open the same web sql database from 2 the browser ui and the web worker.Bombardon
WebSQL is deprecated - so I guess you don't wish to use it (even if it was thread safe). Soon we will have indexedDB support in webWorkers.Stalnaker
H
2

You can't use localStorage or sessionStorage from WebWorkers.

While both are synchronous operations they aren't a real issue for simple data writing and reading. The issue is more relevant at browser start-up, but that's a browser implementation issue.

Take a look at this, it should help: http://www.nczonline.net/blog/2012/04/25/the-performance-of-localstorage-revisited/

Honeysucker answered 20/6, 2012 at 19:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.