lkml.org 
[lkml]   [2003]   [May]   [4]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    /
    Date
    From
    SubjectRe: fcntl file locking and pthreads
    >flock()-based locks work as expected, i.e. only one thread can have an
    >exclusive lock at a time.
    >What would it take to make fcntl work as flock?

    This is because flock locks the inode, not the file descriptor.
    fcntl locks the file descriptor. This is why flock does not
    work over nfs, I suppose. If you share descriptors, you also
    share locks and positions (at least according to the man pages
    of fcntl, dup et al). I don't know what exactly is supposed
    to happen if you open the file twice in two separate threads
    and then lock with fcntl in the first thread. But simply doing

    open()
    pthread_create()
    fcntl()
    (other thread)
    fcntl()
    will probably result in both threads acquiring the lock
    successfully. It would be reasonable IMHO to assume that
    a sequence like

    open()
    pthread_create()
    fcntl()

    (other thread)
    open()
    fnctl() /* lock the newly opened fd */

    would give you what you're after. The only problem being that
    even user space manuals suggest that fcntl can only detect
    that other *processes* hold a file lock. Given the muddy
    nature of what is a thread/process in Linux, this requires
    someone more familiar with the clone stuff to clarify.

    Another issue altogether is why you are trying to sync two
    threads with file locks, but I digress.

    -VJV-
    -
    To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
    the body of a message to majordomo@vger.kernel.org
    More majordomo info at http://vger.kernel.org/majordomo-info.html
    Please read the FAQ at http://www.tux.org/lkml/

    \
     
     \ /
      Last update: 2005-03-22 13:35    [W:22.690 / U:0.212 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site