3ac73c8881
git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@1713 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
72 lines
1.9 KiB
Plaintext
72 lines
1.9 KiB
Plaintext
=================================================================
|
|
Logtalk - Object oriented extension to Prolog
|
|
Release 2.28.2
|
|
|
|
Copyright (c) 1998-2006 Paulo Moura. All Rights Reserved.
|
|
=================================================================
|
|
|
|
|
|
% start by loading the loading the example:
|
|
|
|
| ?- logtalk_load(atomic(loader)).
|
|
...
|
|
|
|
|
|
% send three asynchronous messages whose corresponding methods perform output operations:
|
|
|
|
| ?- threaded_call(nasty1::io(alpha), [noreply]), threaded_call(nasty1::io(digit), [noreply]), threaded_call(nasty1::io(alpha), [noreply]).
|
|
|
|
a0ab1bc2c3ddefef45gg6hh7ii8jkjk9
|
|
llmmnnopopqqrrsstztzyyxxwwuv
|
|
uv
|
|
|
|
Yes
|
|
|
|
|
|
% the same three asynchronous messages but making them atomic for the receiver object:
|
|
|
|
| ?- threaded_call(nasty1::io(alpha), [atomic, noreply]), threaded_call(nasty1::io(digit), [atomic, noreply]), threaded_call(nasty1::io(alpha), [atomic, noreply]).
|
|
|
|
abcdefghijklmnopqrstzyxwuv
|
|
0123456789
|
|
abcdefghijklmnopqrstzyxwuv
|
|
|
|
Yes
|
|
|
|
|
|
% send three asynchronous messages whose corresponding methods perform database updates
|
|
% (this may or may not work, most likely will throw an exception):
|
|
|
|
| ?- threaded_call(nasty1::update_db(_), [noreply]), threaded_call(nasty1::update_db(_), [noreply]), threaded_call(nasty1::update_db(_), [noreply]).
|
|
|
|
No
|
|
|
|
|
|
% the same three asynchronous messages but making them atomic for the receiver object
|
|
% (this should always work):
|
|
|
|
| ?- threaded_call(nasty1::update_db(_), [atomic, noreply]), threaded_call(nasty1::update_db(_), [atomic, noreply]), threaded_call(nasty1::update_db(_), [atomic, noreply]).
|
|
|
|
Yes
|
|
|
|
|
|
% a better solution is to declare predicates that need to be thread syncronized as "atomic",
|
|
% as exemplified in object "nasty2":
|
|
|
|
| ?- nasty2::(io(alpha), io(digit), io(alpha)).
|
|
|
|
abcdefghijklmnopqrstzyxwuv
|
|
0123456789
|
|
abcdefghijklmnopqrstzyxwuv
|
|
|
|
Yes
|
|
|
|
|
|
| ?- nasty2::(update_db(X), update_db(Y), update_db(Z)).
|
|
|
|
X = 1
|
|
Y = 2
|
|
Z = 3
|
|
|
|
Yes
|