Windows是否允许同时写入文件
Does Windows allow simultaenous writing to a file?
我使用Qt创建了一个c++程序,它可以写入文件。这个程序可能会有多个实例,每个实例都通过本地网络访问文件。
我使用QFile::ReadWrite
作为我的文件打开选项。如果一个进程以这种模式打开文件,我发现另一个进程也可以打开它进行写入。我使用file.write(text)
写入文件。如果两个过程同时尝试这样做,会发生什么?Windows能处理这个问题吗?
我想知道是否需要使用Window的CreateFile(...)
重新实现,并使用0作为共享模式?
谢谢。
Qt是开源的,所以只需查看内部(qfsfleengine_win.cpp):
bool QFSFileEnginePrivate::nativeOpen(QIODevice::OpenMode openMode)
{
...
// All files are opened in share mode (both read and write).
DWORD shareMode = FILE_SHARE_READ | FILE_SHARE_WRITE;
...
// Create the file handle.
fileHandle = CreateFile((const wchar_t*)fileEntry.nativeFilePath().utf16(),
accessRights,
shareMode,
&securityAtts,
creationDisp,
FILE_ATTRIBUTE_NORMAL,
NULL);
因此,除了"不在乎"之外,Qt不提供任何文件共享功能。
相关文章:
- 如何在公共头文件中向库的用户公开枚举,同时在内部使用它?
- 是否有一个标准函数可以打印/监视stdin文件的内容,同时将数据留在stdin中
- 多个线程/进程是否可以在不同步的情况下同时从/写入文件的非重叠区域?
- 如何编译同时使用 MPI 和 HDF5 的C++文件?
- C++ 使用简单的代码同时写入文件和控制台输出
- 使用 c++ 同时读取和写入同一文件
- 如何在 c++ 中同时使用 'fstream' 写入和读取文件
- C++-将stdout/stderr复制到文件,同时保留控制台输出
- 如何在读取/写入文件的同时异步读取/写入Beast websocket
- 文件I/O使用C++同时打开两个文件
- C++生成文件,同时分离声明和实现
- 使用c++在文件中同时写入
- C++ 文件 I/O - 无法同时读取/写入?
- 如果我使用c++11功能编译一个文件,同时将其链接到一个没有c++11编译器选项编译的库,会有什么问题吗
- 如何仅搜索文件夹(同时使用boost遍历目录)
- 编写视频文件并同时播放
- 在c++中包含c头文件,同时保持功能
- 一个文件可以同时是可执行文件(EXE)和动态链接库(DLL)吗?
- 如何输入某个文件,同时将某些部分分配到不同的变量中
- 使用Boost Spirit解析文本文件,同时跳过它的大部分