akeniade / csharp-sqlite

Automatically exported from code.google.com/p/csharp-sqlite
Other
0 stars 0 forks source link

Default threading mode should be the same as in native version (Multi-thread), or should be clearly defined in FAQ. #156

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Problem:
Default threading mode in current version is 'Serialized'. It differs from 
default mode in original SQLite version ('Multi-thread'). And the only way to 
know about that is to check sqlite3_threadsafe result in runtime.

Best solution would be to use Multi-thread mode by default.
Other possible solution is to describe this difference in FAQ.

What steps will reproduce the problem?

Attached console application shows availabale behaviors.

What is the expected output? What do you see instead?

Expected behaviour:
  Sqlite3.sqlite3_threadsafe() should return 1 (Multi-thread mode)
  Both RunTest(true) and RunTest(false) should complete

Actual behaiour:
  Sqlite3.sqlite3_threadsafe() returns 2 (Serialized mode)
  RunTest(true) - works as intended
  RunTest(false) - hangs forever

What version of the product are you using? On what operating system?

Windows 7 (64-bit), csharp-sqlite_3_7_7_1_71.zip

References:

http://www.sqlite.org/faq.html#q6 - states:
But in order to be thread-safe, SQLite must be compiled with the 
SQLITE_THREADSAFE preprocessor macro set to 1. Both the Windows and Linux 
precompiled binaries in the distribution are compiled this way.

http://www.sqlite.org/threadsafe.html (section Run-time selection of threading 
mode) - describes the use of SQLITE_OPEN_NOMUTEX flag to override default 
threading mode. This is used in attached sample.

Original issue reported on code.google.com by iyu...@gmail.com on 14 May 2012 at 5:40

Attachments:

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
The FAQ is incorrect.  Only  SQLITE_THREADSAFE=2 is supported;

SQLITE_THREADSAFE=1 sets the default threading mode to Serialized. 
SQLITE_THREADSAFE=2 sets the default threading mode to Multi-threaded.

Original comment by noah.hart@gmail.com on 14 May 2012 at 9:02

GoogleCodeExporter commented 8 years ago
Both SQLite official pages 
(
http://www.sqlite.org/faq.html#q6
http://www.sqlite.org/threadsafe.html
)
state that SQLITE_THREADSAFE=1 is default for precompiled binaries.

Official FAQ does not define that it is Multi-thread or Serialized mode.
Official page about thread-safety says that 1 - Serialized mode.
So my original bug-report was wrong abount mode names.
So I agree with statement:
1 - Serialized
2 - Multi-threaded

http://code.google.com/p/csharp-sqlite/wiki/FrequentlyAskedQuestions
now states that only Multi-threaded mode (2) is supported.

sqlite3_threadsafe() in csharp-sqlite returns 2 by default (Multi-threaded). 
That  proves your FAQ is correct. And that differs default csharp-sqlite 
behavior from default official SQLite version.

In this mode single Sqlite3.sqlite3 instance can not be used in different 
threads at all. Sample application proves that.

I wonder what happens with csharp-sqlite when connection is opened with 
SQLITE_OPEN_NOMUTEX flag, as it is done in the sample application.

So it seems this bug-report should be feature request instead:
Allow reusing of single Sqlite3.sqlite3 instance in different threads.
In sample application only one thread works with single Sqlite3.sqlite3 
instance at the same time, but it hangs.

Most probably supporting SQLITE_THREADSAFE=1 (Serialized mode) by default will 
solve the problem.

Original comment by iyu...@gmail.com on 16 May 2012 at 1:29

GoogleCodeExporter commented 8 years ago
Nice analysis, and agreed, feature request;  
Closing Issue .. please reopen on ClientVoice if this mode is needed:

http://csharpsqlite.uservoice.com/forums/41270-general

Original comment by noah.hart@gmail.com on 16 May 2012 at 1:48

GoogleCodeExporter commented 8 years ago
I did some further research on this issue.

Native SQLite version compiled with SQLITE_THREADSAFE=2 allows reusing of 
database instance in another thread. I assume its just not threadsafe.

So my problem was not caused by SQLITE_THREADSAFE mode, and I don't need 
SQLITE_THREADSAFE=1 mode at the moment.

Instead of this I found some bugs in managed version that was causing my 
problems. Opened bug report about that: 
http://code.google.com/p/csharp-sqlite/issues/detail?id=159

Attached native SQLite version compiled with SQLITE_THREADSAFE=2 for x86 
architecture.

Original comment by iyu...@gmail.com on 17 May 2012 at 8:33

Attachments: