>>So what you're saying is that once about every 4000 times the program executes, that different iterations of this program try to modify the same data file at the same time, causing an error?
>
>It happen at the same time many times in this 4000 times. It's just that sometimes, I get this error message.
>
>I know APPEND BLANK is doing a lock for a fraction of a second in the file header but I thought INSERT INTO was not applying any lock.
>
>If INSERT INTO is applying a file header lock than I'll have to implement a locking sequence. Any idea?
How about this piece of pseudocode, which is basically a pseudocode implementation of UNIX semaphores using VFP's ability to create, destroy, and detect dbf files.
before accessing database a.dbf:
If sema_a.dbf exists then
loop until it is destroyed
end if
(* file sema_a.dbf either did not exist, or has been destroyed by this point in the code *)
Create sema_a.dbf (* note that the contents and structure of this file are
not important - only that it exists *)
access database, modify whatever you need. When you are done:
Destroy sema_a.dbf
What this does:
Consider this scenario:
code piece 1 accesses a.dbf. before doing so it creates the file sema_a.dbf
before code piece 1 is finished with a.dbf, code piece 2 requires access to a.dbf.
code piece 2 sees that the file sema_a.dbf exists. It then knows it must wait, because some other independant piece of code needs access to the file.
code piece 2 then waits until sema_a.dbf is destroyed, at which point code piece 1 is finished and code piece 2 can have free reign to modify a.dbf any way it wants.
Effectively, you are using the presence or absence of sema_a.dbf as a boolean variable which can be shared between multiple, independant pieces of code.
Does this help?
Précédent
Suivant
Répondre
Voir le fil de ce thread
Voir le fil de ce thread à partir de ce message seulement
Voir tous les messages de ce thread
Voir tous les messages de ce thread à partir de ce message seulement