Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 13 Jul 2020 21:40:38 +0700
From:      Eugene Grosbein <eugen@grosbein.net>
To:        "Wall, Stephen" <stephen.wall@redcom.com>, "freebsd-hackers@freebsd.org" <freebsd-hackers@freebsd.org>
Subject:   Re: mutex locking on file descriptors?
Message-ID:  <e0a2b90c-fb7a-abf3-97e1-d4570144b375@grosbein.net>
In-Reply-To: <0ae4590637e54a479228b38a823535a8@redcom.com>
References:  <0ae4590637e54a479228b38a823535a8@redcom.com>

next in thread | previous in thread | raw e-mail | index | archive | help
13.07.2020 21:19, Wall, Stephen wrote:

> I've been told by a co-worker that a freebsd developer once told him that mutex locking
> on socket descriptors was not necessary to avoid issues with multiple threads reading and writing.
> I would like to confirm this is true of file descriptors as well,
> and in particular of device driver file descriptors, before I abandon them in my code.
> The driver in question is a simple `usb_fifo_methods` type driver.

This heavily depends on exact "issues" you are try to avoid, amount of data wrote or read,
used protocol and driver.

In some cases, for some types of descriptors there is atomicy for small writes.
But in general you need some kind of locking. Else you may get unexpected results,
f.e. some part of data read by one thread and another part by another thread.





Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?e0a2b90c-fb7a-abf3-97e1-d4570144b375>