Logtalk 2.29.1 files.

git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@1744 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
pmoura
2006-12-28 13:03:34 +00:00
parent 7316eb490c
commit d79dd807e6
301 changed files with 6700 additions and 998 deletions

View File

@@ -0,0 +1,19 @@
=================================================================
Logtalk - Object oriented extension to Prolog
Release 2.29.1
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 "synchronized" predicate directive to cope with methods that
have side-effects.
The object defined in the example source file, "sync.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 "synchronized" predicate
directive. This predicate uses a counter that you might need to adjust,
depending on your Prolog compiler and computer performance.

View File

@@ -0,0 +1,57 @@
=================================================================
Logtalk - Object oriented extension to Prolog
Release 2.29.1
Copyright (c) 1998-2006 Paulo Moura. All Rights Reserved.
=================================================================
% start by loading the loading the example:
| ?- logtalk_load(sync(loader)).
...
% send three asynchronous messages whose corresponding methods perform output operations:
| ?- threaded_ignore(nasty1::io(alpha)), threaded_ignore(nasty1::io(digit)), threaded_ignore(nasty1::io(alpha)).
a0ab1bc2c3ddefef45gg6hh7ii8jkjk9
llmmnnopopqqrrsstztzyyxxwwuv
uv
Yes
% send three asynchronous messages whose corresponding methods perform database updates
% (this may or may not work, most likely will throw an exception):
| ?- threaded_ignore(nasty1::update_db(_)), threaded_ignore(nasty1::update_db(_)), threaded_ignore(nasty1::update_db(_)).
No
% the best solution is to declare predicates that need to be thread synchronized as "synchronized",
% as exemplified in object "nasty2":
| ?- threaded_ignore(nasty2::io(alpha)), threaded_ignore(nasty2::io(digit)), threaded_ignore(nasty2::io(alpha)).
abcdefghijklmnopqrstzyxwuv
0123456789
abcdefghijklmnopqrstzyxwuv
Yes
| ?- threaded_call(nasty2::update_db(_)), threaded_call(nasty2::update_db(_)), threaded_call(nasty2::update_db(_)).
Yes
| ?- threaded_exit(nasty2::update_db(X)), threaded_exit(nasty2::update_db(Y)), threaded_exit(nasty2::update_db(Z)).
X = 1
Y = 2
Z = 3
Yes

View File

@@ -0,0 +1,13 @@
:- initialization(
logtalk_load(
sync)).
/*
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(
sync, [xmlsref(standalone)])).
*/

View File

@@ -0,0 +1,121 @@
:- object(nasty1).
:- info([
version is 1.1,
author is 'Paulo Moura',
date is 2006/11/26,
comment is 'Simple example for illustrating the problems with lack of thread synchronization when calling methods 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.1,
author is 'Paulo Moura',
date is 2006/11/26,
comment is 'Simple example for using the "synchronized" predicate directive for multi-threading methods with side-effects.']).
:- threaded.
:- public(update_db/1).
:- synchronized(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).
:- synchronized(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.