Re: shareDenyNone
From: Joseph M. Newcomer (newcomer_at_flounder.com)
Date: 05/06/04
- Next message: KS: "Re: Closing a dialog box"
- Previous message: Neel Roy: "Re: Tracking mouse coordinates!"
- In reply to: Jonathan Wood: "shareDenyNone"
- Next in thread: Jonathan Wood: "Re: shareDenyNone"
- Reply: Jonathan Wood: "Re: shareDenyNone"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 06 May 2004 14:51:25 -0400
Once you do this, it becomes your responsibility to ensure that simultaneous writers
cannot ever corrupt the data. This means you have to do explicit file locking yourself
(LockFileEx, UnlockFileEx) on portions of the file. In addition, the following code is
always guaranteed to be unreliable:
LONGLONG n = f.GetFileSize();
if(n < SOME_MAX_CONSTANT)
... go ahead and do it
because between the time GetFileSize was done and n was found to be some known value and
the time you tested it, some other thread got scheduled, ran at high priority, and added a
megabyte of data to the file.
The correctness of data is not guaranteed if you are reading data while another thread is
writing in the same area. You could get any mix of old and new data. That's why you have
to do LockFileEx. Even when extending (note that you can lock areas beyond the
end-of-file, so that you are guaranteed you are the only one appending). And if two
threads are writing, all bets are completely off. You are likely to end up with garbage.
joe
On Thu, 6 May 2004 10:00:05 -0600, "Jonathan Wood" <jwood@softcircuits.com> wrote:
>Hello,
>
>I have had some customers request that my software be able to open files
>that are in use by other applications. Previously, I was opening files with
>the shareDenyWrite attribute. If I change this to shareDenyNone, then I am
>able to open the files in question.
>
>Does anyone have any experience with shareDenyNone? I'm concerned I would
>start to read the file and problems could arise if another process was
>writing to it at the same time. Currently, my application also checks that
>the file is not too big, but that could change if another process was
>writing to the file as I read it.
>
>Any thoughts?
>
>Thanks.
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
- Next message: KS: "Re: Closing a dialog box"
- Previous message: Neel Roy: "Re: Tracking mouse coordinates!"
- In reply to: Jonathan Wood: "shareDenyNone"
- Next in thread: Jonathan Wood: "Re: shareDenyNone"
- Reply: Jonathan Wood: "Re: shareDenyNone"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|