Thread: Synchronization problem, sort of producer/consumer

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Jan 2012
    Posts
    2

    Synchronization problem, sort of producer/consumer

    Hi,

    I have 5 sqlite tables, using the sqlite3 api.

    In one process I'm moving a record from table 1 to 2, 2 to 3, etc. I'm doing the move with a lock on the table so no one else touches it during the move.

    In the second process I'm going through the tables once per function call, trying to select the record to see which table the record is in. I try to select from table 1, if it's found I return the value 1. If not, I try table 2, etc. If it is not found in any table (the record can be moved back from table 2 to table 1 but then it gets deleted from table 1 so it would be considered deleted once it leaves table 2 and I don't have to find it in table 1 to be correct) then I return 0.

    The second process does not use any locks.

    I only want the second process to return 0 if the record is truly not there - if it's in transition between tables I don't want to return 0 by accident.

    I think that since I'm locking the tables during transitions, and since I'm only allowed to move (and select) in the forward direction (1->2->3->4->5) I should not be missing the record. Is this a simple programming 101 problem that I'm just not remembering?

    I'm wondering if anyone knows what this problem would be called (I know it's not quite producer/consumer, but some name like that) that I could look up to see it solved in a textbook?

    Any info is appreciated. Thanks.

    JP
    Last edited by jpenney; 01-25-2012 at 03:00 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Producer Consumer concurrency problem
    By Kurjack in forum C Programming
    Replies: 0
    Last Post: 10-18-2010, 02:21 PM
  2. consumer producer problem with threads
    By nabi in forum C Programming
    Replies: 3
    Last Post: 08-27-2010, 09:51 AM
  3. Producer/Consumer Problem
    By AvengedGoat in forum C++ Programming
    Replies: 5
    Last Post: 03-21-2010, 12:33 PM
  4. pthread producer consumer problem
    By Amit Chikorde in forum C Programming
    Replies: 1
    Last Post: 01-17-2007, 07:39 PM
  5. Producer consumer problem
    By traz in forum C Programming
    Replies: 2
    Last Post: 11-08-2002, 08:04 PM