/* Same as tableread2, but perturbation of threads occurs at a different place (note that the number of threads created is number-of-threads * number-of-iterations -- so keep number-of-iterations small! */ :- import for/3 from basics. :- thread_shared num_is/1. :- dynamic num_is/1. :- assert((concurr_initialize(tableread(N,_)):- retractall(num_is(_)), assert(num_is(N)), (tableread_table(_),fail;true))). :- table tableread_table/1. :- thread_shared tableread_table/1. % This isn't good tabling style, but does make a good test. tableread_table(X):- test_thread_number(Threads), num_is(N), Spin is 10 * N, for(X,1,N), make_duplicate_goals(Threads,spin(Spin),List), exec_goals(List,Ids), join_list(Ids). spin(N):- num_is(N), for(_X,1,N), fail. spin(_). tableread(N,Str):- for(_X,1,N), tableread_table(_), fail. tableread(_,Str):- tableread_table(X), writeln(Str,X), fail. tableread(_,_).