升压进程间file_lock不与多个进程工作 [英] boost interprocess file_lock does not work with multiple processes

查看:164
本文介绍了升压进程间file_lock不与多个进程工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎有一个带提升的问题:: ::间file_lock

I seem to be having an issue with boost::interprocess::file_lock

我有过程1的基本上

    boost::interprocess::file_lock test_lock("testfile.csv");
    test_lock.lock();
    sleep(1000);
    test_lock.unlock();

当我运行,而第一个进程正在休眠的第二过程中,我发现,我仍然能够读取testfile.csv。更糟的是,我甚至可以覆盖它。

When I run a second process while the first process is sleeping, I find that I am still able to read testfile.csv. What's worse, I can even overwrite it.

我是misinter preting如何file_lock的作品?我是IM pression,调用.lock()给它在文件和prevents独占锁从读取任何其他进程/修改文件下。

Am I misinterpreting how file_lock works? I was under the impression that calling .lock() gives it exclusive lock over the file and prevents any other process from read/modifying the file.

推荐答案

file_lock不是锁定的文件。它是一个使用文件作为其背衬技术互斥对象。该文件的内容基本上是不相关的;什么是相关的是,指向该文件fil​​e_lock的所有实例将尊重锁的锁定特点。

file_lock is not for locking a file. It is a mutual exclusion object that uses a file as its backing technology. The contents of the file are basically irrelevant; what is relevant is that all instances of a file_lock pointing to that file will respect the locking characteristics of the lock.

对于任何互斥类型的对象,锁本身是为了保护或以其他方式计访问某些等资源。

As with any mutex-type object, the lock itself is there to protect or otherwise meter access to some other resource.

它的没有的做文件的文件系统的保护。

It has nothing to do with filesystem protection of files.

<一个href=\"http://www.boost.org/doc/libs/1_55_0/doc/html/interprocess/synchronization_mechanisms.html#interprocess.synchronization_mechanisms.file_lock\"相对=nofollow>参考

这篇关于升压进程间file_lock不与多个进程工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆