{"action":"opened","issue":{"url":"https://api.github.com/repos/mmottl/sqlite3-ocaml/issues/25","repository_url":"https://api.github.com/repos/mmottl/sqlite3-ocaml","labels_url":"https://api.github.com/repos/mmottl/sqlite3-ocaml/issues/25/labels{/name}","comments_url":"https://api.github.com/repos/mmottl/sqlite3-ocaml/issues/25/comments","events_url":"https://api.github.com/repos/mmottl/sqlite3-ocaml/issues/25/events","html_url":"https://github.com/mmottl/sqlite3-ocaml/issues/25","id":276747318,"number":25,"title":"Notice about thread-safety","user":{"login":"paurkedal","id":144070,"avatar_url":"https://avatars3.githubusercontent.com/u/144070?v=4","gravatar_id":"","url":"https://api.github.com/users/paurkedal","html_url":"https://github.com/paurkedal","followers_url":"https://api.github.com/users/paurkedal/followers","following_url":"https://api.github.com/users/paurkedal/following{/other_user}","gists_url":"https://api.github.com/users/paurkedal/gists{/gist_id}","starred_url":"https://api.github.com/users/paurkedal/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/paurkedal/subscriptions","organizations_url":"https://api.github.com/users/paurkedal/orgs","repos_url":"https://api.github.com/users/paurkedal/repos","events_url":"https://api.github.com/users/paurkedal/events{/privacy}","received_events_url":"https://api.github.com/users/paurkedal/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2017-11-25T12:27:12Z","updated_at":"2017-11-25T12:27:12Z","closed_at":null,"author_association":"NONE","body":"For the `db` and `stmt` types there is a notice not to use them \"WITHIN THREADS OTHER THAN THE ONE THAT CREATED IT\".  Comparing with [the Sqlite3 documentation on thread safety](https://sqlite.org/threadsafe.html):\r\n\r\n> SQLite supports three different threading modes:\r\n>\r\n> 1. Single-thread. In this mode, all mutexes are disabled and SQLite is unsafe to use in more than a single thread at once.\r\n>\r\n> 2. Multi-thread. In this mode, SQLite can be safely used by multiple threads provided that no single database connection is used simultaneously in two or more threads.\r\n>\r\n> 3. Serialized. In serialized mode, SQLite can be safely used by multiple threads with no restriction.\r\n\r\nIn the worst case scenario, sqlite3 is compiled for single-thread mode, in which case it would not be safe to use the library simultaneously from different threads even using different handles.  This is probaby not very common, though.  The default mode is serialized, and I would guess most distribution at least enables multi-thread.\r\n\r\nIf we assume at least multi-thread mode, then the requirement seems too strong.  In particular, it should be safe to use a `db` or `stmt` from different threads, as long as access is locked by a per-`db` and per-`stmt` mutex.  This is relevant to applications using `Lwt_preemptiev` and `Async.In_thread`.  In `Async.In_thread` there is a `thread` argument which may help, but `Lwt_preemptive` does not give control over which thread to use.\r\n\r\nCan we assume the OCaml bindings does not bring in any additional threading issues?  If so, maybe it would be better to refer to or relay the Sqlite3 documentation on the point?"}}
{"actor":{"display_login":"paurkedal"}}