From b1b6156f6dae67744e53a78bee5b32bba3901f2b Mon Sep 17 00:00:00 2001 From: pmoura Date: Fri, 29 Dec 2006 09:54:42 +0000 Subject: [PATCH] Logtalk 2.29.1 files. git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@1747 b08c6af1-5177-4d33-ba66-4b1c6b8b522a --- Logtalk/examples/threads/atomic/NOTES.txt | 19 ---- Logtalk/examples/threads/atomic/SCRIPT.txt | 71 ------------ Logtalk/examples/threads/atomic/atomic.lgt | 121 --------------------- Logtalk/examples/threads/atomic/loader.lgt | 13 --- 4 files changed, 224 deletions(-) delete mode 100644 Logtalk/examples/threads/atomic/NOTES.txt delete mode 100644 Logtalk/examples/threads/atomic/SCRIPT.txt delete mode 100644 Logtalk/examples/threads/atomic/atomic.lgt delete mode 100644 Logtalk/examples/threads/atomic/loader.lgt diff --git a/Logtalk/examples/threads/atomic/NOTES.txt b/Logtalk/examples/threads/atomic/NOTES.txt deleted file mode 100644 index addf85e1e..000000000 --- a/Logtalk/examples/threads/atomic/NOTES.txt +++ /dev/null @@ -1,19 +0,0 @@ -================================================================= -Logtalk - Object oriented extension to Prolog -Release 2.28.2 - -Copyright (c) 1998-2006 Paulo Moura. All Rights Reserved. -================================================================= - - -To load this example and for sample queries, please see the SCRIPT file. - -This folder contains a simple multi-threading example illustrating the -use of the "atomic" option on threaded_call/2 calls to cope with methods -that have side-effects. - -The object defined in the example source file, "atomic.lgt", defines a -predicate named waste_time/0 that is used to delay the execuion of goals -in order to better illustrate the semantics of the "atomic" option. This -predicate uses a counter that you might need to adjust, depending on your -Prolog compiler and computer performance. diff --git a/Logtalk/examples/threads/atomic/SCRIPT.txt b/Logtalk/examples/threads/atomic/SCRIPT.txt deleted file mode 100644 index 3ffcef73c..000000000 --- a/Logtalk/examples/threads/atomic/SCRIPT.txt +++ /dev/null @@ -1,71 +0,0 @@ -================================================================= -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 diff --git a/Logtalk/examples/threads/atomic/atomic.lgt b/Logtalk/examples/threads/atomic/atomic.lgt deleted file mode 100644 index 3475912a4..000000000 --- a/Logtalk/examples/threads/atomic/atomic.lgt +++ /dev/null @@ -1,121 +0,0 @@ - -:- object(nasty1). - - :- info([ - version is 1.0, - author is 'Paulo Moura', - date is 2006/04/14, - comment is 'Simple example for using the "atomic" option for multi-threading calls with side-effects.']). - - :- threaded. - - :- public(update_db/1). - :- mode(update_db(-integer), one). - :- info(update_db/1, [ - comment is 'Perform a database update with a long delay between retracting the old information and asserting the new one.', - argnames is ['New']]). - - :- private(db/1). - :- dynamic(db/1). - - :- public(io/1). - :- mode(io(+atom), one). - :- info(io/1, [ - comment is 'Write some characters to the standard output stream with a long delay between each write operation.', - argnames is ['Chars']]). - - db(0). - - update_db(New) :- - retract(db(Old)), - waste_time, - New is Old + 1, - waste_time, - assertz(db(New)). - - io(alpha) :- - write(a), waste_time, write(b), waste_time, write(c), waste_time, write(d), waste_time, write(e), - write(f), waste_time, write(g), waste_time, write(h), waste_time, write(i), waste_time, write(j), - write(k), waste_time, write(l), waste_time, write(m), waste_time, write(n), waste_time, write(o), - write(p), waste_time, write(q), waste_time, write(r), waste_time, write(s), waste_time, write(t), - write(z), waste_time, write(y), waste_time, write(x), waste_time, write(w), waste_time, write(u), - write(v), nl. - - io(digit) :- - write(0), waste_time, write(1), waste_time, write(2), waste_time, write(3), waste_time, write(4), - write(5), waste_time, write(6), waste_time, write(7), waste_time, write(8), waste_time, write(9), nl. - - waste_time :- - between(1, 10000, _), - fail. - waste_time. - - between(Lower, _, Lower). - between(Lower, Upper, Integer) :- - Lower < Upper, - Next is Lower + 1, - between(Next, Upper, Integer). - -:- end_object. - - -:- object(nasty2). - - :- info([ - version is 1.0, - author is 'Paulo Moura', - date is 2006/04/14, - comment is 'Simple example for using the "atomic" option for multi-threading calls with side-effects.']). - - :- threaded. - - :- public(update_db/1). - :- atomic(update_db/1). - :- mode(update_db(-integer), one). - :- info(update_db/1, [ - comment is 'Perform a database update with a long delay between retracting the old information and asserting the new one.', - argnames is ['New']]). - - :- private(db/1). - :- dynamic(db/1). - - :- public(io/1). - :- atomic(io/1). - :- mode(io(+atom), one). - :- info(io/1, [ - comment is 'Write some characters to the standard output stream with a long delay between each write operation.', - argnames is ['Chars']]). - - db(0). - - update_db(New) :- - retract(db(Old)), - waste_time, - New is Old + 1, - waste_time, - assertz(db(New)). - - io(alpha) :- - write(a), waste_time, write(b), waste_time, write(c), waste_time, write(d), waste_time, write(e), - write(f), waste_time, write(g), waste_time, write(h), waste_time, write(i), waste_time, write(j), - write(k), waste_time, write(l), waste_time, write(m), waste_time, write(n), waste_time, write(o), - write(p), waste_time, write(q), waste_time, write(r), waste_time, write(s), waste_time, write(t), - write(z), waste_time, write(y), waste_time, write(x), waste_time, write(w), waste_time, write(u), - write(v), nl. - - io(digit) :- - write(0), waste_time, write(1), waste_time, write(2), waste_time, write(3), waste_time, write(4), - write(5), waste_time, write(6), waste_time, write(7), waste_time, write(8), waste_time, write(9), nl. - - waste_time :- - between(1, 100000, _), - fail. - waste_time. - - between(Lower, _, Lower). - between(Lower, Upper, Integer) :- - Lower < Upper, - Next is Lower + 1, - between(Next, Upper, Integer). - -:- end_object. diff --git a/Logtalk/examples/threads/atomic/loader.lgt b/Logtalk/examples/threads/atomic/loader.lgt deleted file mode 100644 index d76562fe7..000000000 --- a/Logtalk/examples/threads/atomic/loader.lgt +++ /dev/null @@ -1,13 +0,0 @@ - -:- initialization( - logtalk_load( - atomic)). - -/* -If you intend to use the FOP XSL:FO processor for generating PDF documenting -files, comment the directive above and uncomment the directive below - -:- initialization( - logtalk_load( - atomic, [xmlsref(standalone)])). -*/