Re: Use of mutex in persistency store

Jan Wielemaker <[email protected]>
Newsgroups gmane.comp.ai.prolog.swi
Message-ID <[email protected]>
Wouter,

On 10/28/2013 07:58 PM, Wouter Beek wrote:
> Hi,
>
> In the documentation for the persistency
> library<http://www.swi-prolog.org/pldoc/doc/home/vnc/prolog/lib/swipl/library/persistency.pl>,
> the following code occurs:
> ~~~{.pl}
> current_user_role(Name, Role) :-
>    with_mutex(user_db, user_role(Name, Role)).
> ~~~
> I do not get the use of with_mutex/1 here. Could reading from the
> persistency store cause troubles in another thread, and if so how?

Suppose another thread calls set_user_role(+Name, +Role) which does
a retractall and assert.  Now, there is a point in time where there
is no user role defined and user_role/2 will fail.  If you swap the
assert and retract, there is a point in time that there are two roles.

The clean solution is a transactional Prolog database as I described
for CICLOPS last year.  Without, you need both a mutex to set and to
retrieve the current value.  Mutexes for retrieving values 
deterministically isn't too bad, but non-deterministically it is easy
to have situations where the lock is held long.

	Cheers --- Jan


>
> ---
> Cheers!,
> Wouter.
>
> E-mail: [email protected]
> WWW: www.wouterbeek.com
> Tel.: 0647674624
> -------------- next part --------------
> HTML attachment scrubbed and removed
> _______________________________________________
> SWI-Prolog mailing list
> [email protected]
> https://lists.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.