opening same file twice
opening same file twice
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
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
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?
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?
- Kaeru Gaman
- Addict
- Posts: 4826
- Joined: Sun Mar 19, 2006 1:57 pm
- Location: Germany
Re: opening same file twice
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.
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.
oh... and have a nice day.
Re: opening same file twice
I want to try recordlocking - for that the file should be accesible.
- Kaeru Gaman
- Addict
- Posts: 4826
- Joined: Sun Mar 19, 2006 1:57 pm
- Location: Germany
Re: opening same file twice
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...?
let the clients send a message to the central handler, the handler itself writes it to disk.
or did I misunderstand now...?
oh... and have a nice day.
Re: opening same file twice
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)
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)
- Kaeru Gaman
- Addict
- Posts: 4826
- Joined: Sun Mar 19, 2006 1:57 pm
- Location: Germany
Re: opening same file twice
do you use a DataBase system?
those should handle this internally...
but ok, having this in mind, it maybe worth a feature request...
those should handle this internally...
but ok, having this in mind, it maybe worth a feature request...
oh... and have a nice day.
Re: opening same file twice
This would be to avoid a database system (sqlite locks the entire database = all tables together)
Could this maybe done with an API call?
Could this maybe done with an API call?
- Kaeru Gaman
- Addict
- Posts: 4826
- Joined: Sun Mar 19, 2006 1:57 pm
- Location: Germany
Re: opening same file twice
I would suggest introducing a new flag for OpenFile, like #PB_File_NonExclusive.
oh... and have a nice day.
Re: opening same file twice
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.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)
Re: opening same file twice
Yes, I needed tooKaeru Gaman wrote:I would suggest introducing a new flag for OpenFile, like #PB_File_NonExclusive.
http://www.purebasic.fr/english/viewtop ... 13&t=41197
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Re: opening same file twice
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?