/* A table is created sequentially, creating conditional answers. Then after the table is completed, threads read from the table concurrently N times. This tests concurrent reads as well as concurrent tabletry. Threads are sharing a table, but this shouldn't matter for now. */ :- 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))). :- thread_shared tableread_table/1. :- table tableread_table/1. tableread_table(X):- num_is(N), for(X,1,N), p(X). :- thread_shared p/1. :- table p/1. p(X):- tnot(p(X)). tableread(N,Str):- for(_X,1,N), tableread_table(_), fail. tableread(_,Str):- tableread_table(X), writeln(Str,X), fail. tableread(_,_).