Is this a read/write race condition?

A

antonyliu2002

I do not quite understand the race condition.

As I posted a couple of days ago, I create a PDF on the fly in my web
application at regular intervals. Users will be able to download the
PDF file.

Suppose, at the time when my application is in the process of
generating the PDF file (which takes around 2.5 minutes), a user tries
to download it, will this be a problem?

I checked the Lock method of FileStream. The description of this
method says:

Prevents other processes from changing the FileStream while permitting
read access.
From the description, read access is permitted even if the stream is
locked. So, it looks like the creation of the PDF file and the
downloading of this file can happen at the same time without a
problem, right?

Thanks.
 
L

Lloyd Sheen

I do not quite understand the race condition.

As I posted a couple of days ago, I create a PDF on the fly in my web
application at regular intervals. Users will be able to download the
PDF file.

Suppose, at the time when my application is in the process of
generating the PDF file (which takes around 2.5 minutes), a user tries
to download it, will this be a problem?

I checked the Lock method of FileStream. The description of this
method says:

Prevents other processes from changing the FileStream while permitting
read access.

locked. So, it looks like the creation of the PDF file and the
downloading of this file can happen at the same time without a
problem, right?

Thanks.

Perhaps you could do one of the following:

1. Create the PDF with a different name than the name which users will
download. Once the PDF is created then delete the old one and change the
name of the new one to the download name.

2. Disable the mechanism (button ??) to download the file while a new on is
being created.

Hope this helps,

Lloyd Sheen
 
A

antonyliu2002

Perhaps you could do one of the following:

1. Create the PDF with a different name than the name which users will
download. Once the PDF is created then delete the old one and change the
name of the new one to the download name.

2. Disable the mechanism (button ??) to download the file while a new on is
being created.

Hope this helps,

Lloyd Sheen

Hi, Lloyd,

Thanks. your idea 1 is absolutely a good solution, since changing the
file name is only a flash of second in an application. That will
certainly reduce the probability of race condition otherwise imposed
in a 2.5-minute duration when the PDF file is being created.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top