Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

READ/WRITE and RELEASE handling in Linux device driver against multithreaded application

While writing a driver, I came across a issue mentioned below.

Given a multithreaded application accessing the same device file through same FD. Consider that between the calls to OPEN and RELEASE, there are some resources (say mutex) held mutually by the thread-group. These resources are used during the READ/WRITE calls, and then eventually given up or destroyed during RELEASE.

If there is one thread accessing the resource during READ/WRITE and another thread simultaneously invokes the RELEASE by calling close, how is it assured by the VFS that the RELEASE is not called until there is at least one thread in the READ, WRITE, or like. What mechanism is handling this protection?

like image 860
user31986 Avatar asked Feb 26 '26 14:02

user31986


1 Answers

The kernel layer above the device drivers keeps track of how many references to an open file exist and does not call the release function until all of those references have been closed. This is somewhat documented in LDD3: http://tjworld.net/books/ldd3/#TheReleaseMethod

like image 145
Benjamin Leinweber Avatar answered Mar 02 '26 14:03

Benjamin Leinweber



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!