[Lazarus] semaphores
Antonio Fortuny
a.fortuny at sitasoftware.lu
Tue Feb 14 11:41:24 CET 2012
Le 14/02/2012 11:22, Lukasz Sokol a écrit :
> On 14/02/2012 09:48, Antonio Fortuny wrote:
>
>>> System-wide solutions for Linux is the *Unix-way*, is to create a
>>> lock-file;
>> Got it.
>>> If you create one on a tmpfs mounted directory,
>> What do you call a "tmpfs mounted directory" ? I'm only a pascal
>> programmer not a system guy
> Usually in /tmp, or by examining the output of 'mount'.
>
>>> it will all happen in memory, hence no hard-drive storage access
>>> will happen (unless moved to swap, but in your case it won't ever
>>> happen) so all you need to do is check for lock file existence.
>> Does it mean that every process will have to create the file ? An
>> open-close sequence checking the IOResult would be enough ?
> No, only the process that uses the resource, creates the file, that
> /i think/ should be enough, others only see if file exists.
No, all launched processes will have to do their work on the shared
resource. In that way I wonder if an open on the control file with a
deny share wouldn't work. This means that the locking algorithm must
provide some kind of local loop in which a test is made with the open
file and a sleep if the open fails. Something like (in pseudo-code)
// do initializing stuff
while (not file error) and (not time elapsed) do begin
open file (no share)
if not open error then
break;
wait
Dec(max time)
continue
end;
if still file open error then begin
post an error message
exit
end;
// do whatever to do with the resource
// release clie (close it);
>
> Also, for other examples of inter-process communication, you may
> want to read about DBUS maybe ?
Once something works I prefer to keep it as simple as possible.
> L.
>
>>> (IMHO) There is also futex (Fast Userspace muTEX) but I don't know
>>> much about that one; http://en.wikipedia.org/wiki/Futex
>>>
>>> HTH. L.
>>>
>>>
>
> --
> _______________________________________________
> Lazarus mailing list
> Lazarus at lists.lazarus.freepascal.org
> http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
>
More information about the Lazarus
mailing list