473,378 Members | 1,140 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

FileOpen and FILE_SARE_WRITE

Hello there.

What does happen when two threads write to one file opened with
attribute FILE_SHARE_WRITE? Let's that both threads save an array of 10
elements as follows:
THR1: WriteFile(handle1, array1, 10);
THR2: WriteFile(handle2, array2, 10);

where handle1 and handle2 are handles to the same file opened with the
FILE_SHARE_WRITE attribute.

Will these operation cause two arrays will be saved consecutively, or
perhaps will they become completely mixed in a file? Do I have to use a
synchronization like mutex or critical sections, or is this implemented
on the WriteFile level somehow?

Thanks a lot,
Peter.

Jul 13 '07 #1
3 1129

"A n g l e r" <p k o n i u s z @ h o t m a i l . c o mwrote in message
news:f7**********@news.onet.pl...
Hello there.

What does happen when two threads write to one file opened with attribute
FILE_SHARE_WRITE? Let's that both threads save an array of 10 elements as
follows:
THR1: WriteFile(handle1, array1, 10);
THR2: WriteFile(handle2, array2, 10);

where handle1 and handle2 are handles to the same file opened with the
FILE_SHARE_WRITE attribute.

Will these operation cause two arrays will be saved consecutively, or
perhaps will they become completely mixed in a file? Do I have to use a
synchronization like mutex or critical sections, or is this implemented on
the WriteFile level somehow?
Each HANDLE maintains its own file position. Writing to one won't move the
other one forward, so one array will end up written on top of the other. I
think as long as WriteFile succeeds in a single call, you'll get one or the
other array in its entirety. But if you end up needing a sequence of
partial writes you could end up with part of each array.
>
Thanks a lot,
Peter.

Jul 26 '07 #2
Each HANDLE maintains its own file position. Writing to one won't
move
the other one forward, so one array will end up written on top of the
other. I think as long as WriteFile succeeds in a single call,
you'll
get one or the other array in its entirety. But if you end up
needing
a sequence of partial writes you could end up with part of each
array.

Hi there.

I guess that I should have tested what I wanted - that would be the
quickest way to tease out the answer. Anyway, let me explain that I'm
talking here about accessing HID device as a file. Does it change
anything?
Cheers,
Peter.

Jul 26 '07 #3

"A n g l e r" <p k o n i u s z @ h o t m a i l . c o mwrote in message
news:f8**********@news.onet.pl...
>Each HANDLE maintains its own file position. Writing to one won't move
the other one forward, so one array will end up written on top of the
other. I think as long as WriteFile succeeds in a single call, you'll
get one or the other array in its entirety. But if you end up needing
a sequence of partial writes you could end up with part of each array.


Hi there.

I guess that I should have tested what I wanted - that would be the
quickest way to tease out the answer. Anyway, let me explain that I'm
That would have a race condition, so you might not actually get the right
answer.
talking here about accessing HID device as a file. Does it change
anything?
Well, you should test whether you can open multiple handles at once. Some
devices can't be opened multiple times regardless of sharing options. After
that, everything depends on the driver.
Aug 6 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: MR BIGLESWORTH | last post by:
Hi, I have A FileOpen command that opens A file outside of the local folder (where my program is). That works fine, but; I want to create a file in the local folder after that 1st file is opened,...
0
by: Wendy Attenberger | last post by:
We are using the FileOpen method to read through a .css file. It is dropping the period in front of a .css class name. (whenever the line begins with a period...it just drops it.) FYI...It...
11
by: CM | last post by:
I'm learning VB6 from a book. The following code is supposed to open a simple text file I created - putting the text into my VB text box. Private Sub cmdOpen_Click() CommonDialog1.ShowOpen If...
2
by: zurg | last post by:
Hi! I have a specific problem - I need to take some informations from a .txt file from another computer... I use OpenFile and the program runs perfectly... But when I run it second time I get an...
2
by: AussieRules | last post by:
Hi, Is it possible to add a text box to capture some extra data in the fileopendialog control. If not, is it is to mock up a copy of it ?
0
by: jharikrishna | last post by:
How to use filestreams in c# How to open the fileopen window how to read the text in that file.
0
by: Subhankar | last post by:
Hi, I am trying to open a MS Project residing in a MS SQL Server. I have the following code for the FileOpen: projectApp.FileOpen("<ChouOister>\\Test Project 2", false, 0, null, null, null,...
1
by: ckb | last post by:
Hi, I need to get the fileopen saveas dialogbox in javascript.I have used the but i want to extract the location ang the file name that the user chooses in my code for further processing once the...
2
by: keane | last post by:
i have using one batch file in my VB.NET bin Directory, it loads when form load event. The Output from the batch file stored into some log file.when i am going to write those results by using...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.