skip (AT) pobox (DOT) com (Skip Montanaro) wrote in message news:<727daa7e.0308260745.48468756 (AT) posting (DOT) google.com>...
Quote:
If I have a db object as defined above shared between two threads, under
what conditions do I need to acquire a lock to access it safely? Here are
the four cases:
* Both threads only read |
No lock needed.
Quote:
* One thread reads, the other writes |
Lock needed.
Quote:
* Both threads only write |
Lock needed.
Quote:
* Both threads perform both reads and writes |
Lock needed.
Quote:
It seems clear to me that no locking is necessary in the first case and that
it is absolutely required in the last two cases. What about the second
case? If thread one reads while thread two is writing, can the reader see
an inconsistent state in the db object? |
Yes.
Quote:
How does this extend to the case of two processes, where each has opened the
database file independently? |
If each have opened the database file independently, the entire
database session (open to close) should probably be locked, as
the two processes won't share an underlying database cache, and
so may see inconsistent data.
Regards,
--keith
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Keith Bostic bostic (AT) sleepycat (DOT) com
Sleepycat Software Inc. keithbosticim (ymsgid)
118 Tower Rd. +1-781-259-3139
Lincoln, MA 01773 http://www.sleepycat.com