threading and win32

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

threading and win32

Wilson Yeung
I wasn't doing a very good job paying attention to the FAQ about
threading and SQLite when I wrote a bunch of code on win32.

I'm sharing sqlite3 database handles between threads, although I am
ensuring that no two threads are executing against the sqlite3
database handle at the same time.

The threads are in fact interleaving, and the sqlite3 database handle
is indeed being shared between the two threads, and everything is
working as I'd like it to work...

Is the warning about threads in the FAQ specifically apply to Linux
systems?  Or can we pretty much say that my code is going to
eventually break on win32 and I'm lucky that it hasn't already?

Wilson
Reply | Threaded
Open this post in threaded view
|

Re: threading and win32

Chris Schirlinger
I'm using threads and SQLite on a Win32 system

I can tell you that things may work 100% for ages, then one day, the
moons align and the threads will fall over each others feet

It may happen later, rather than sooner, and may not even happen in
your lifetime, but it'll happen :)


> I wasn't doing a very good job paying attention to the FAQ about
> threading and SQLite when I wrote a bunch of code on win32.
>
> I'm sharing sqlite3 database handles between threads, although I am
> ensuring that no two threads are executing against the sqlite3
> database handle at the same time.
>
> The threads are in fact interleaving, and the sqlite3 database handle
> is indeed being shared between the two threads, and everything is
> working as I'd like it to work...
>
> Is the warning about threads in the FAQ specifically apply to Linux
> systems?  Or can we pretty much say that my code is going to
> eventually break on win32 and I'm lucky that it hasn't already?
>
> Wilson



Reply | Threaded
Open this post in threaded view
|

Re: threading and win32

John LeSueur-2
In reply to this post by Wilson Yeung
On 10/19/05, Wilson Yeung <[hidden email]> wrote:

>
> I wasn't doing a very good job paying attention to the FAQ about
> threading and SQLite when I wrote a bunch of code on win32.
>
> I'm sharing sqlite3 database handles between threads, although I am
> ensuring that no two threads are executing against the sqlite3
> database handle at the same time.
>
> The threads are in fact interleaving, and the sqlite3 database handle
> is indeed being shared between the two threads, and everything is
> working as I'd like it to work...
>
> Is the warning about threads in the FAQ specifically apply to Linux
> systems? Or can we pretty much say that my code is going to
> eventually break on win32 and I'm lucky that it hasn't already?
>
> Wilson
>

What version of sqlite are you using? Newer versions are supposed to
complain about being used in two different threads. As Chris said, you
should probably follow the documentation on this point, as the behavior
of threads is such that errors can often be hidden, until under stress.

John
Reply | Threaded
Open this post in threaded view
|

Re: threading and win32

Wilson Yeung
SQLite 3.2.6.  I will do as both you and Chris say.

Thanks. :)

Wilson
Reply | Threaded
Open this post in threaded view
|

Re: threading and win32

René Tegel
In reply to this post by Wilson Yeung
Hi,

There was a recent discussion about this, with the subject "Problems
with threadsafe opt correction #2623"

On 5/9 2005 Richard wrote:
"The restriction that a DB handle can only be used from a single
thread is currently only enforced on Unix, because Unix boxes
are the only place where using DB handles in multiple threads is
a problem.
-- D. Richard Hipp <[hidden email]>
"

 From personal experience it seems sqlite is completely safe in
multi-threaded environments when shared the same database handle on
windows platforms, provided that you use an adequate locking mechanism.

The drawback is portability to other platforms that implement threading
different and are not safe on concurrent file access, even if
well-sequenced. On unix sqlite enforces a database handle to be used by
the same thread as that opened it. Some people claimed having no
problems, but this seems os/kernel dependent.

rene



Wilson Yeung wrote:

>I wasn't doing a very good job paying attention to the FAQ about
>threading and SQLite when I wrote a bunch of code on win32.
>
>I'm sharing sqlite3 database handles between threads, although I am
>ensuring that no two threads are executing against the sqlite3
>database handle at the same time.
>
>The threads are in fact interleaving, and the sqlite3 database handle
>is indeed being shared between the two threads, and everything is
>working as I'd like it to work...
>
>Is the warning about threads in the FAQ specifically apply to Linux
>systems?  Or can we pretty much say that my code is going to
>eventually break on win32 and I'm lucky that it hasn't already?
>
>Wilson
>  
>