From ai@solvo.ru Fri Sep  7 08:32:40 2001
Received: from grace.solvo.ru (root@grace.solvo.ru [195.201.44.100])
	by swi.psy.uva.nl (8.11.2/8.11.2) with ESMTP id f876Wdv16581
	for <prolog@swi.psy.uva.nl>; Fri, 7 Sep 2001 08:32:39 +0200 (MET DST)
Received: from elbrus (elbrus.solvo.ru [195.201.44.16])
	by grace.solvo.ru (8.8.8/8.8.8) with SMTP id KAA22375
	for <prolog@swi.psy.uva.nl>; Fri, 7 Sep 2001 10:32:37 +0400
Message-ID: <004b01c13766$df080080$102cc9c3@elbrus>
From: "Lyosha" <ai@solvo.ru>
To: <prolog@swi.psy.uva.nl>
Date: Fri, 7 Sep 2001 10:32:30 +0400
Organization: Solvo
MIME-Version: 1.0
Content-Type: multipart/alternative;
	boundary="----=_NextPart_000_0048_01C13788.65E59830"
X-Priority: 3
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook Express 5.50.4522.1200
Disposition-Notification-To: "Lyosha" <ai@solvo.ru>
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4522.1200
Subject: [SWIPL] Multithreading bug?

This is a multi-part message in MIME format.

------=_NextPart_000_0048_01C13788.65E59830
Content-Type: text/plain;
	charset="Windows-1252"
Content-Transfer-Encoding: quoted-printable

Hi,

I am using SWI-Prolog Version 4.0.9 undex linux=20
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=20
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]).




------=_NextPart_000_0048_01C13788.65E59830
Content-Type: text/html;
	charset="Windows-1252"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content=3D"text/html; charset=3Dwindows-1252" =
http-equiv=3DContent-Type>
<META content=3D"MSHTML 5.00.3315.2870" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#d8d0c8>
<DIV><FONT face=3D"Courier New CYR">Hi,</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3D"Courier New CYR">I am using SWI-Prolog Version 4.0.9 =
undex=20
linux </FONT></DIV>
<DIV><FONT face=3D"Courier New CYR">compiled with multi-thread support. =
The=20
following</FONT></DIV>
<DIV><FONT face=3D"Courier New CYR">example&nbsp;gives =
different&nbsp;results=20
depending on how</FONT></DIV>
<DIV><FONT face=3D"Courier New CYR">many iterations it goes through. =
With=20
iterations(5000)</FONT></DIV>
<DIV><FONT face=3D"Courier New CYR">it almost always works (both threads =
give=20
finished</FONT></DIV>
<DIV><FONT face=3D"Courier New CYR">messages). With iterations(10000) it =
locks up=20
</FONT></DIV>
<DIV><FONT face=3D"Courier New CYR">sometimes (I guess at mutex lock). =
And with=20
high</FONT></DIV>
<DIV><FONT face=3D"Courier New CYR">iteration numbers it never works =
(the number=20
may</FONT></DIV>
<DIV><FONT face=3D"Courier New CYR">depend on your system performance). =
So, I=20
wonder -</FONT></DIV>
<DIV><FONT face=3D"Courier New CYR">can&nbsp;anyone can see where I am=20
wrong?</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT=20
face=3D"Courier New =
CYR">test:-<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
thread_create( thread, _Id1, [] =
),<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
thread_create( thread, _Id2, [] ).</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3D"Courier New CYR">iterations(20000).</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3D"Courier New CYR">thread=20
:-<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
iterations(N),<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; forall(=20
between(1,N,_),<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
with_mutex(mut1, true )),<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
thread_self(ID),</FONT></DIV>
<DIV><FONT face=3D"Courier New =
CYR">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
writef('thread %w finished\n',[ID]).</FONT></DIV>
<DIV><FONT face=3D"Courier New CYR"></FONT>&nbsp;</DIV>
<DIV><FONT face=3D"Courier New =
CYR"><BR>&nbsp;</DIV></FONT></BODY></HTML>

------=_NextPart_000_0048_01C13788.65E59830--

