Hey there, Lance and others interested in threadsafe FreeFile
Isnt this really a threadsafe way to use "FreeFile"
We can call it "collision detection"
If more than one thread is executing a code as above "at the same time"
that is FreeFile is returning lets say #1 to all three thread,
Thread_one Opens the file, Thread_One will exit its loop with success
Thread_two and Thread_three will fail because they try to use a FilNumber
that is in use. (I dont know how it works internally but this failure must
be detected before any access to the filesystem is made)
So Thread_two and Thread_three has to try again.
Lets say that they both get the same FileNumber #2.
Tread_two (or Thread_three) will succeed and the other thread has to try again.
Am I wrong or am I just wrong...?
--
I dont know if 'FreeFile' ever return an error-code.
I dont know if Err=55 always is reported as the error-code
(File Already Open), but I tend to never use the errorcode, I tend to accept
only 'SUCCESS' as a valid response.
------------------
Fred
mailto:[email protected][email protected]</A>
http://www.oxenby.se
[This message has been edited by Fred Oxenby (edited January 30, 2001).]
Isnt this really a threadsafe way to use "FreeFile"
We can call it "collision detection"
Code:
Retry = 0 Do ErrClear:FilNr& = FreeFile ErrClear:Open FileName$ For ...... as #FilNr& If ErrClear = 0 Then Exit Do If Retry > 50 then Failure Incr Retry:Sleep 100 Loop
that is FreeFile is returning lets say #1 to all three thread,
Thread_one Opens the file, Thread_One will exit its loop with success
Thread_two and Thread_three will fail because they try to use a FilNumber
that is in use. (I dont know how it works internally but this failure must
be detected before any access to the filesystem is made)
So Thread_two and Thread_three has to try again.
Lets say that they both get the same FileNumber #2.
Tread_two (or Thread_three) will succeed and the other thread has to try again.
Am I wrong or am I just wrong...?
--
I dont know if 'FreeFile' ever return an error-code.
I dont know if Err=55 always is reported as the error-code
(File Already Open), but I tend to never use the errorcode, I tend to accept
only 'SUCCESS' as a valid response.
------------------
Fred
mailto:[email protected][email protected]</A>
http://www.oxenby.se
[This message has been edited by Fred Oxenby (edited January 30, 2001).]
Comment