michallenc commented on PR #19110:
URL: https://github.com/apache/nuttx/pull/19110#issuecomment-4681341765

   > > > but this change is wrong. POSIX require file lock is process wide: 
https://pubs.opengroup.org/onlinepubs/7908799/xsh/fcntl.html @michallenc 
@acassis @lupyuen @linguini1
   > > 
   > > 
   > > But process wide locking still works, the commit doesn't change that. It 
fixes the behavior for thread wide locking, which should also work - POSIX is 
not much clear about it, but it also states:
   > > > This command is the same as F_SETLK except that if a shared or 
exclusive lock is blocked by other locks, the thread will wait until the 
request can be satisfied
   > 
   > Linux support two set of file lock API, POSIX defined F_SETLK/F_SETLKW 
require the process wide behaviour:
   > <img alt="image" width="2000" height="170" 
src="https://private-user-images.githubusercontent.com/18066964/606292862-cffd2ec2-52a1-49c5-9754-0ce79ed4ebbc.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3ODExODU3MDQsIm5iZiI6MTc4MTE4NTQwNCwicGF0aCI6Ii8xODA2Njk2NC82MDYyOTI4NjItY2ZmZDJlYzItNTJhMS00OWM1LTk3NTQtMGNlNzllZDRlYmJjLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNjA2MTElMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjYwNjExVDEzNDMyNFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTYwNjZlNzgzY2JjZGYyMWZjMGYzNGQwMjgwMmY5MjExYjQ3MzY1YmJkZDNjMjgyZjA2ZjUxNmE1NjI2Mzg3ZTMmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JnJlc3BvbnNlLWNvbnRlbnQtdHlwZT1pbWFnZSUyRnBuZyJ9.MM-wKENEPlCAPKtlctoZ-5qnl_uF6q1Gbu49xr9UOm4";>
   > 
   > > And the Linux example clearly shows the locking should also work for 
threads - it seems unlikely Linux breaks POSIX in this case, so I think the 
change is fine.
   > 
   > The above behavior is defined by flock: 
https://stackoverflow.com/questions/9462532/multiple-threads-able-to-get-flock-at-the-same-time
   > 
   > > I have also now noticed lock for SHM is undefined according to POSIX
   > > > When the file descriptor fildes refers to a shared memory object, the 
behaviour of fcntl() is the same as for a regular file except the effect of the 
following values for the argument cmd are unspecified: F_SETFL, F_GETLK, 
F_SETLK, and F_SETLKW.
   > > 
   > > 
   > > But again, Linux supports it, so we should too.
   > 
   > so, we should getpid for F_SETLKx and gettid for flock.
   
   I will need to check how Linux behaves if locks are used directly with 
`fcntl`. It's weird the behavior would not apply for threads, what's the point 
of locks then.
   
   Using `getpid` for one and `gettid` for other will be hard I think, `flock` 
is basically just a layer above `fcntl` in NuttX. We would probably need 
different low level implementations.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to