From mboxrd@z Thu Jan 1 00:00:00 1970 From: hle@owl.eu.com (Hugo Lefeuvre) Date: Mon, 4 Jun 2018 18:31:31 -0400 Subject: develoment workflow: how to avoid duplicate work ? In-Reply-To: <12368.1528128607@turing-police.cc.vt.edu> References: <20180529030706.GD1845@hle-laptop.local> <80132.1527564735@turing-police.cc.vt.edu> <20180530025657.GB1919@hle-laptop.local> <22501.1527692619@turing-police.cc.vt.edu> <20180531014432.GA3722@hle-laptop.local> <20180603192336.GV14048@gavran.carpriv.carnet.hr> <20180603222556.GB20060@hle-laptop.local> <20180604033303.GX14048@gavran.carpriv.carnet.hr> <12368.1528128607@turing-police.cc.vt.edu> Message-ID: <20180604223131.GA1981@hle-laptop.local> To: kernelnewbies@lists.kernelnewbies.org List-Id: kernelnewbies.lists.kernelnewbies.org > > > The vfs documentation states: release() is "called when the last > > > reference to an open file is closed". > > > > > > Let's say we have a program with threads T1 and T2. > > > > > > - T1 calls ioctl on a file descriptor FD. > > > - (on another processor) T2 closes FD. > > > > > > Since the last reference to FD was closed by T2, release is called. > > That's subtly wrong. T2 releases its reference to the file descriptor. > > > > But while release is being called, the ioctl call from T1 may still > > > be running, right ? > > Remember that ioctl needs an open FD as well - so the ioctl() grabs its own > reference, and then *that* reference to the file descriptor stays in place at > least until the ioctl() return. At *that* point, the reference count goes to > zero and the file is actually closed. Well, my assumption was that T1 and T2 would share the exact same file descriptor. For example, a main thread T0 would call open() to get the file descriptor, and then spawn T1 and T2 which would both use this common FD. Let's say: - main thread T0 calls open() and gets FD 3 - T0 spawns T1 and T2 - T1 calls ioctl(3, ...) or read(3, ...)/write(3, ...) - (on another processor) T2 calls close(3) Do you mean that the ioctl/read/write call increments the reference count in this case ? It would mean that these syscalls aren't really using passed FD but instead create duplicates to make sure the open file description won't be freed during their execution, right ? Cheers, hugo -- Hugo Lefeuvre (hle) | www.owl.eu.com 4096/ 9C4F C8BF A4B0 8FC5 48EB 56B8 1962 765B B9A8 BACA -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 488 bytes Desc: not available URL: