Subject: [SWIPL] Multithreading bug?

From: "Lyosha" <[email-masked]>
Date: Fri, 7 Sep 2001 10:32:30 +0400

Hi,

I am using SWI-Prolog Version 4.0.9 undex linux 
compiled with multi-thread support. The following
example gives different results depending on how
many iterations it goes through. With iterations(5000)
it almost always works (both threads give finished
messages). With iterations(10000) it locks up 
sometimes (I guess at mutex lock). And with high
iteration numbers it never works (the number may
depend on your system performance). So, I wonder -
can anyone can see where I am wrong?

test:-
        thread_create( thread, _Id1, [] ),
        thread_create( thread, _Id2, [] ).

iterations(20000).

thread :-
        iterations(N),
        forall( between(1,N,_),
                  with_mutex(mut1, true )),
        thread_self(ID),
        writef('thread %w finished\n',[ID]).