简体   繁体   中英

boost interprocess file_lock can't lock file it does not own

When I use boost file_lock to try to lock files it doesn't own with lock() or lock_sharable(), it throws an exception. Is there any way for it to lock a file owned by a different user so it can modify it safely (the modifying user has correct write permissions).

The fact that you're throwing an exception means that it's not waiting for any existing exclusive or shareable locks to be released (this should be a blocking call). Make sure that you actually have the file-name correct, or check the error code in the boost::interprocess_exception that is being thrown using either the what() , get_native_error() , or get_error_code() methods. For instance, you could be having a file-permissions problem, or the file may not exist, etc. An exception is not thrown because of lock contention, so that's not your problem ...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM