Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 23 Apr 1997 01:08:06 +0200 (MET DST)
From:      "Alex Fenyo (eowyn)" <fenyo@email.enst.fr>
To:        freebsd-hackers@freebsd.org
Cc:        jb@cimlogic.com.au
Subject:   fd locking problem with libc_r ?
Message-ID:  <199704222308.BAA20563@nikopol.enst.fr>

next in thread | raw e-mail | index | archive | help

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 ?)

The problem is the same with writev().

Many thanks,
Alexandre Fenyo




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