Re: fcntl file locking and pthreads

Mikhail Kruk (meshko@cs.brandeis.edu)
Sun, 4 May 2003 18:04:48 -0400 (EDT)


> 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 */

actually what I have is:
thread 0:
pthread_create() (1)
pthread_create() (2)

thread 1:
open()
fcntl()

thread 2:
open()
fcntl()

etc

and they all succeed. Even though the file descriptors are different.

> 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

Unfortunately man pages I have don't even mention thread vs process.

> 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.

You digress, but I feel like I have to justify myself now :)
Those threads used to be processes and now want be threads with minimal
modifications. The files that are locked are still used by other processes
too.

-
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/