Record Locking Help ....

Ben Duncan bns
Mon Aug 15 10:30:15 PDT 2005


I thought about semaphores, but the risk of a deadly embrace seems
to increase with them (just research on their usage seems to indicate that).

I am thinking, at least with the mmap and LOCKBYTE, I have accomplished the same
thing.  The LOCKS will be atomic, any READ with a lock will be done by a this process:

A: Position pointer in file
B: fcntl lock  the LOCKBYTE
    B1: Failed, return failed status
C: READ record
    C1: test LOCKBYTE
        TRUE: return <record is lock> status
        FALSE:
           Set UID, PID and LOCKBYTE
           Force WRITE immediate of header
           Release fcntl Lock
D: return DATA

This way I have non-blocking I/O with self advisory locks.


fcntl is already in tdb, so I thought I would just continue using the same logic.

Roger Oberholtzer wrote:
<SNIP>

> As long as your locks are atomic. This will eliminate race conditions.
> As was mentioned by Kurt, semaphores are good for this. If you use
> semaphores on a record, you should not also need the fcntl locking as
> well. Start with 'man semctl', 'man semopt' and 'man semget'.
> 
> +????????????????????????????+???????????????????????????????+
> ? Roger Oberholtzer          ?   E-mail: roger at opq.se        ?
> ? OPQ Systems AB             ?      WWW: http://www.opq.se/  ?
> ? Kapellgr?nd 7              ?                               ?
> ? P. O. Box 4205             ?    Phone: Int + 46 8   314223 ?
> ? 102 65 Stockholm           ?   Mobile: Int + 46 733 621657 ?
> ? Sweden                     ?      Fax: Int + 46 8   314223 ?
> +????????????????????????????+???????????????????????????????+
> 
> _______________________________________________
> Linux-users mailing list ( Linux-users at linux-sxs.org )
> Unsub/Password/Etc: http://mail.linux-sxs.org/cgi-bin/mailman/listinfo/linux-users
> 
> Need to chat further on this subject? Check out #linux-users on irc.linux-sxs.org !
> 
> .
> 

-- 
Ben Duncan   - VersAccounting Software LLC 336 Elton Road  Jackson MS, 39212
"Never attribute to malice, that which can be adequately explained by stupidity"
        - Hanlon's Razor




More information about the Linux-users mailing list