• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Shaired Reading Locks??

 
James Turner
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I have been wondering how it may be possible to create a shaired reading lock on the database and exclusive write lock? I.e. many threads can read data, even the same row at the same instant, but writes are exclusive and occur synchroniously.

This would be done in a way, where by, writes must wait till reads are complete to write, and writes must wait till other writes are complete to write, but reads can occur at any point, even together, as long as no writes are occuring.

This type of DB access is called Repeatable Read, I was wondering what would be a simple way of simulating it in the Data class to prevent data corruption but keeping performance up.

This may be over the top, but it would at least be a complete implementation.

James.
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 12007
215
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi James,

To have a "repeatable read", you need to have a concept of a transaction. The read (and, presumably, the update) occur within the same transaction. In the middle of that transaction, no other thread can update the specified record.

An easy way of handling this would be to have some sort of logical lock at the record level, so that once one client owns the lock on the record, then no other thread can modify it.

Now if only the provided interface gave us some ability to lock individual records .

Regards, Andrew
 
Mogens Nidding
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Andrew, that's a really good answer! A strong hint rather than a total giveaway.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic