[Interprocess] Problem with file_lock on Linux
The following code
#include
El 27/08/2015 a las 13:25, Jan Niklas Hasse escribió:
The following code
#include
#include <iostream> #include <fstream> int main() { std::ofstream file("test.lock"); boost::interprocess::file_lock flock("test.lock"); std::cout << flock.try_lock(); std::cout << flock.try_lock() << std::endl; }
outputs 10 on Windows and 11 on Linux. Shouldn't it also print 10 on Linux or am I missunderstanding file_lock? I've also tried locking from different threads, but no luck.
File locks are "process-wide resources", this means that there is no guarantee about thread synchronization within the same process. It only works to synchronize two different processes. Although the documentation speaks about processes, it should reflect this limitation appropriately. In windows, file locks do support intra-process synchronization whereas in UNIX only process-wide synchronization is supported. In any case you are in undefined behavior territory, trying to lock twice from the same thread, even from the same process for file locks. Best, Ion
El 28/08/2015 a las 12:10, Ion Gaztañaga escribió:
File locks are "process-wide resources", this means that there is no guarantee about thread synchronization within the same process. It only works to synchronize two different processes. Although the documentation speaks about processes, it should reflect this limitation appropriately. In windows, file locks do support intra-process synchronization whereas in UNIX only process-wide synchronization is supported.
In any case you are in undefined behavior territory, trying to lock twice from the same thread, even from the same process for file locks.
For more information, see: file:///C:/Data/Libs/boost/libs/interprocess/doc/html/interprocess/synchronization_mechanisms.html#interprocess.synchronization_mechanisms.file_lock.file_lock_not_thread_safe Ion
Am 28.08.2015 um 12:32 schrieb Ion Gaztañaga:
For more information, see:
file:///C:/Data/Libs/boost/libs/interprocess/doc/html/interprocess/synchronization_mechanisms.html#interprocess.synchronization_mechanisms.file_lock.file_lock_not_thread_safe
Ion
I see, thank you :)
participants (2)
-
Ion Gaztañaga
-
Jan Niklas Hasse