Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 25 Apr 1997 08:00:00 +1000 (EST)
From:      John Birrell <jb@cimlogic.com.au>
To:        fenyo@email.enst.fr
Cc:        freebsd-hackers@freebsd.org, jb@cimlogic.com.au
Subject:   Re: fd locking problem with libc_r ?
Message-ID:  <199704242200.IAA01941@freebsd1.cimlogic.com.au>
In-Reply-To: <199704222308.BAA20563@nikopol.enst.fr> from Alex Fenyo at "Apr 23, 97 01:08:06 am"

next in thread | previous in thread | raw e-mail | index | archive | help
[Sorry for the delay, it's been one of those weeks!]

Alex Fenyo wrote:
> 
> Hello,
> 
> I encountered a possibly bug in libc_r.
> 
> Suppose you have 2 threads and a file descriptor, for instance a socket.
> 
> Suppose too that nothing is to be read on the fd (the daemon on
> the other side didn't feed the socket), but we can write on it (the
> daemon on the other side reads on it).
> 
> The first thread performs a call to read() on fd.
> 
> LATER, the second thread performs a call to write() on the fd.
> 
> The problem is that : the write call in the second thread will always
> be performed after something can be read by the first thread.
> 
> It's because in src/lib/libc_r uthread_write.c,
> there is a read-write lock on the fd :
> ------------------------------------------------------------
>         if ((ret = _thread_fd_lock(fd, FD_RDWR, NULL,
>             __FILE__, __LINE__)) == 0) {
> ------------------------------------------------------------
> 
> I wonder why is there such a read-write lock when just a write
> lock would be sufficient (and would solve the problem) ???
> Perhaps it's because a write lock wouldn't be sufficient ???
> (I can't find a reason for that ?)

I think you are right, the read and write locks are independent
and they only exist at all because of the need to do things non-blocking
in user-space.

This will be solved when rfork() can be used to thread a user process.
I'm not sure where John Dyson got to with this... Maybe the vfork()
problems got in the way. 8-(

> 
> The problem is the same with writev().

Yep.

> 
> Many thanks,
> Alexandre Fenyo
> 
> 
Regards,


-- 
John Birrell - jb@cimlogic.com.au; jb@netbsd.org; jb@freebsd.org
CIMlogic Pty Ltd, 119 Cecil Street, South Melbourne Vic 3205, Australia
Tel +61 3 9690 6900 Fax +61 3 9690 6650 Mob +61 418 353 137



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199704242200.IAA01941>