[Cbe-oss-dev] [PATCH 2/3] libspe2: Fix blocking in spe_in_mbox_write w/ SPE_MBOX_ANY_NONBLOCKING

Arnd Bergmann arnd at arndb.de
Sat Apr 14 05:27:36 EST 2007


On Friday 13 April 2007, Kazunori Asayama wrote:
> The current implementation of spe_in_mbox_write in libspe2 has
> possibility to be blocked even if SPE_MBOX_ANY_NONBLOCKING is passed
> as behavior flag, when another thread calls spe_in_mbox_write with
> SPE_MBOX_ALL_BLOCKING at the same time (*see the scenario below).
> 
> To solve this problem essentially and simply, I propose to wait for
> the wbox FD by select() and perform non-blocking write(), instead of
> checking the "wbox_stat" node.

Both solutions sound rather inefficient to me, either way you double
the number of syscalls for one access mode:

- in the broken code, the wbox_stat node is read, which is not only
  racy as you point out, but also means doing two syscalls for one
  read.
- in your new code, you do an extra syscall for the blocking case,
  which is probably even more common, so you are slowing that down.
  Worse, you use the 'select' call, not 'poll', so the code breaks
  if you try to increase the number of open file descriptors beyond
  1024. No library should ever use select().

I'd propose instead to have two separate file descriptors, one for
blocking and one for non-blocking access. You'd still open them
only on first use, so most applications should not waste additional
resources, but you can always transfer your data with a single
syscall.

	Arnd <><



More information about the cbe-oss-dev mailing list