No announcement yet.

Wait a minute... (FreeFile)

  • Filter
  • Time
  • Show
Clear All
new posts

  • Lance Edmonds
    It looks like a reasonable approach.

    Personally, I'd wrap that in an EnterCriticalSection/LeaveCriticalSection just be 100% sure that context switches are eradicated from the mix.

    BTW, R&D have said that making FREEFILE threadsafe is quite high on the wish list.

    PowerBASIC Support
    mailto:[email protected][email protected]</A>

    Leave a comment:

  • Fred Oxenby
    started a topic Wait a minute... (FreeFile)

    Wait a minute... (FreeFile)

    Hey there, Lance and others interested in threadsafe FreeFile

    Isnt this really a threadsafe way to use "FreeFile"
    We can call it "collision detection"
      Retry = 0
       ErrClear:FilNr& = FreeFile
       ErrClear:Open FileName$ For ...... as #FilNr&
       If ErrClear = 0 Then Exit Do
       If Retry > 50 then Failure
       Incr Retry:Sleep 100
    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.

    mailto:[email protected][email protected]</A>

    [This message has been edited by Fred Oxenby (edited January 30, 2001).]