lkml.org 
[lkml]   [2003]   [May]   [4]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectRE: fcntl file locking and pthreads
Date

> CLONE_FILES is an argument to clone(), I'm using pthreads and I don't
> know if LinuxThreads implementation of pthreads gives me control of
> how clone is called. Anyway, if I understand what CLONE_FILES does,
> it should be given to clone, because threads do have to be able
> to share file
> descriptors, probably. But not the locks!

What if I have an application where requests are written to files. Thread A
comes along and notices a job in a file, so it locks the file and reads the
job. The job will require some network I/O, so the thread goes on to do
other things. Later on, thread B notices the network I/O has completed, so
it needs to write to the file, release the lock, and close the file.

Making locks local to specific threads is contrary to the whole purpose of
threads. Work that needs to be done on a file descriptor is supposed to be
doable by any thread.

This is something that can be solved with application code. Just keep a
table of all your file locks and consult the table before attempting to
acquire a lock from the system. This is no different than the housekeeping
required around 'malloc' (or more accurately 'sbrk').

DS


-
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:0.101 / U:0.160 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site