file-locking

Is std::ifstream thread-safe & lock-free?

独自空忆成欢 提交于 2019-12-18 05:11:55
问题 I intend to perform opening for reading a single file from many threads using std::ifstream. My concern is if std::ifstream is thread-safe & lock-free? More details: I use g++ 4.4 on Ubuntu & Windows XP, 4.0 on Leopard. Each thread creates its own instance of std::ifstream Thanks in advance! 回答1: That is implementation defined. Standard C++ says absolutely nothing about threading, and therefore any assumptions about threads inherently invoke unspecified or implementation defined behavior. We

Reading a file used by another process [duplicate]

安稳与你 提交于 2019-12-17 03:36:25
问题 This question already has answers here : How can I read a file even when getting an “in use by another process” exception? (4 answers) Closed 3 years ago . I am monitoring a text file that is being written to by a server program. Every time the file is changed the content will be outputted to a window in my program. The problem is that I can't use the Streamreader on the file as it is being used by another process . Setting up a Filestream with ReadWrite won't do any good since I cannot

lock text files with passwords [closed]

*爱你&永不变心* 提交于 2019-12-13 09:17:51
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 7 years ago . Is there any way to protect the text file. I want to protect my text files to protect with password. So how is it possible that when client wants to open the text file it asks for password and files can be opened in notepad only after entering the right password. By using this can be make our files secure 回答1:

Create a locked file with boost::interprocess::file_lock

丶灬走出姿态 提交于 2019-12-12 10:45:48
问题 I'd like to use boost::interprocess::file_lock to ensure that files that are written to a directory x by process P1 are not read by process P2 until they are complete. To do this, I'd like to have P1 lock the files with boost::interprocess::file_lock while it's writing them, and then unlock them when it's done. Then P2 can just skip over (and come back to) any files that are locked. The problem I'm having is that it appears that boost::interprocess::file_lock only lets you lock files that

Locking behaviour is different via network shares

心已入冬 提交于 2019-12-12 08:54:08
问题 I have been trying to lock a file so that other cloned services cannot access the file. I then read the file, and then move the file when finished. The Move is allowed by using FileShare.Delete . However in later testing, we found that this approach does not work if we are looking at a network share. I appreciate my approach may not have been the best, but my specific question is: Why does the below demo work against the local file, but not against the network file? The more specific you can

Does `javax.imageio.ImageIO` require file locking?

眉间皱痕 提交于 2019-12-12 01:47:28
问题 My app is saving images into a folder. Simultaneously another piece of software watches over this folder and prints pasted images. Problem I've encountered is that printing app can send on printer half rendered image or doesn't react to saved images at all. I'm using javax.imageio.ImageIO.write(RenderedImage im, String formatName, File output) to save BufferedImage into png format. If locking required please provide a code example with explicit locks. If not explain why. I've tested on

Extra Process file locks

坚强是说给别人听的谎言 提交于 2019-12-11 06:47:56
问题 I have a .NET system where I need to allow files to be locked and unlocked across process boundaries. The model I plan to use is this: User generate a lock token Uses Locks a file with token and refreshes token repeat at #2 as needed Uses unlocks all files by releasing token If uses fails to refresh token in some time-frame, #4 happens automatically Each step can be done from a different process. The question is two fold: is this a reasonable model and are there any readily available tools

How lock a file in windows using c++?

强颜欢笑 提交于 2019-12-10 10:24:57
问题 How can I lock a file in windows to only current thread (no other threads from same process and no other processes) can access (read/write) the file? If it is possible please tell me some fcntl-like solution (solution which locks file having its descriptor). But in any case other solutions are welcome too. 回答1: In Windows, you can open a file with exclusive access with the API function CreateFile and specifying 0 as the share mode. More details at this MSDN link, and this MSDN link. 回答2: Use

Get username of user who has file open on network drive - Microsoft Office Style

二次信任 提交于 2019-12-10 07:39:16
问题 I would like to add user friendly file locking to a software running under Windows (Windows 7 mostly), written in C# . I already achieved the file locking part, by keeping the files in use "open" in the corresponding process. What I now still would like to add is recognition of the user who has a file currently open/locked. The files being accessed lie on a mapped network drive , used by different users on different computers. When a file is locked and a second person tries to open the file,

Log File Monitor

馋奶兔 提交于 2019-12-10 07:30:57
问题 Is is possible to open a text file and read the contents while another application is updating the file, in such a way that it does not cause a lock conflict? I need to monitor a log file from one application which is updated by another application each time an event occurs. I do check if the file is in use before I try to read it, but that does not seem to work in all cases. Thanks, Pieter 回答1: it depends on how the first app open that file. i.e when calling CreateFile API to open a file,