Page 1 of 1
opening same file twice
Posted: Sat Feb 27, 2010 3:46 pm
by t57042
I am trying to open the same file 2 times on the same PC (windows XP) to test multiuser possibility.
The fist process seems to lock the file.
The second openfile or readfile returns 0.
Is there a solution to that?
Richard
Re: opening same file twice
Posted: Sat Feb 27, 2010 5:35 pm
by t57042
After further testing the problem only exists when the file is opened with "openfile".
If the file is opened twice with "readfile" both programs can open the file.
I suppose this is the way it is supposed to be.
Is there a way to open with "openfile" without preventing others from opening tat file?
Re: opening same file twice
Posted: Sat Feb 27, 2010 5:42 pm
by Kaeru Gaman
I thought I read a Feature Request for this...
but I can't find it now...
in my eyes it's correct this way, because write-access has to be exclusive.
why don't you use ReadFile if you want shared access?
[edit]
two times write access can produce unpredictable results.
I would suggest a central File-Handler, that grants single write access to the clients.
a client can send a request to the handler and wait for admittance.
Re: opening same file twice
Posted: Sat Feb 27, 2010 5:58 pm
by t57042
I want to try recordlocking - for that the file should be accesible.
Re: opening same file twice
Posted: Sat Feb 27, 2010 6:00 pm
by Kaeru Gaman
hm... still suggesting a central handler.
let the clients send a message to the central handler, the handler itself writes it to disk.
or did I misunderstand now...?
Re: opening same file twice
Posted: Sat Feb 27, 2010 6:11 pm
by t57042
The idea is to use the first byte of each record to indicate if the record is locked.
So before updating a record - read it - check 1st byte - when not locked write.
I used this protocol before in multi user applications (1 computer with several terminals)
Re: opening same file twice
Posted: Sat Feb 27, 2010 6:23 pm
by Kaeru Gaman
do you use a DataBase system?
those should handle this internally...
but ok, having this in mind, it maybe worth a feature request...
Re: opening same file twice
Posted: Sat Feb 27, 2010 6:32 pm
by t57042
This would be to avoid a database system (sqlite locks the entire database = all tables together)
Could this maybe done with an API call?
Re: opening same file twice
Posted: Sat Feb 27, 2010 6:50 pm
by Kaeru Gaman
I would suggest introducing a new flag for OpenFile, like #PB_File_NonExclusive.
Re: opening same file twice
Posted: Sat Feb 27, 2010 8:18 pm
by Trond
t57042 wrote:The idea is to use the first byte of each record to indicate if the record is locked.
So before updating a record - read it - check 1st byte - when not locked write.
I used this protocol before in multi user applications (1 computer with several terminals)
That won't work. If another application locks the record after the record was read, but before the first byte was checked, there will be havoc.
Re: opening same file twice
Posted: Sun Feb 28, 2010 4:05 pm
by mk-soft
Kaeru Gaman wrote:I would suggest introducing a new flag for OpenFile, like #PB_File_NonExclusive.
Yes, I needed too
http://www.purebasic.fr/english/viewtop ... 13&t=41197
Re: opening same file twice
Posted: Mon Mar 01, 2010 10:47 am
by Mahan
I seem to remember the reason why SQLite has to lock the entire file is that there are OSes where you cannot reliably open a file twice for writing with reliable block-locking. I think this was mainly a Linux issue. And since PB is for Linux too this might be the reason for the limitation?