<P><SPAN>But  using pthreads alone is working fine. </SPAN></P>
<P><SPAN>testthread1 can work under uclibc linux. </SPAN></P>
<P><SPAN><BR><STRONG>program testthread1;</STRONG></SPAN></P>
<P><SPAN>{$mode objfpc}</SPAN></P>
<P><SPAN>uses<BR>  sysutils, pthreads;</SPAN></P>
<P><SPAN>const<BR>  threadcount = 10;<BR>  stringlen = 10000;</SPAN></P>
<P><SPAN>var<BR>   finished : longint;</SPAN></P>
<P><SPAN>threadvar<BR>   thri : longint;</SPAN></P>
<P><SPAN>function myf(p : pointer) : longint;cdecl;</SPAN></P>
<P><SPAN>var<BR>  s : ansistring;</SPAN></P>
<P><SPAN>begin<BR>  Writeln('thread ',longint(p),' started');<BR>  thri:=0;<BR>  while (thri<stringlen) do<BR>    begin<BR>    s:=s+'1';<BR>    inc(thri);<BR>    end;<BR>  Writeln('thread ',longint(p),' finished');<BR>  InterLockedIncrement(finished);<BR>  myf:=0;<BR>end;</SPAN></P>
<P><SPAN>var<BR>   i : longint;<BR>    ThreadID1: ppthread_t;<BR>begin<BR>   Writeln('thread testing',longint(i),' started');<BR>   finished:=0;<BR>   for i:=1 to threadcount do<BR>     pthread_create(@ThreadID1, nil, @myf, Pointer(i));<BR>   while finished<threadcount do ;<BR>   Writeln(finished);<BR>end.<BR> </SPAN><BR><BR><BR><STRONG>program testthread2 using cthreads will crash.</STRONG></P>
<P>{$mode delphi}</P>
<P>uses<BR>   sysutils, cthreads;</P>
<P>const<BR>  threadcount = 100;<BR>  stringlen = 10000;</P>
<P>var<BR>   finished : longint;</P>
<P>threadvar<BR>   thri : longint;</P>
<P>function f(p : pointer) : longint;</P>
<P>var<BR>  s : ansistring;</P>
<P>begin<BR>  Writeln('thread ',longint(p),' started');<BR>  thri:=0;<BR>  while (thri<stringlen) do<BR>    begin<BR>    s:=s+'1';<BR>    inc(thri);<BR>    end;<BR>  Writeln('thread ',longint(p),' finished');<BR>  InterLockedIncrement(finished);<BR>  f:=0;<BR>end;</P>
<P>function myf(p : pointer) : longint;cdecl;</P>
<P>var<BR>  s : ansistring;</P>
<P>begin<BR>  Writeln('thread ',longint(p),' started');<BR>  thri:=0;<BR>  while (thri<stringlen) do<BR>    begin<BR>    s:=s+'1';<BR>    inc(thri);<BR>    end;<BR>  Writeln('thread ',longint(p),' finished');<BR>  InterLockedIncrement(finished);<BR>  myf:=0;<BR>end;</P>
<P>var<BR>   i : longint;<BR>   t: TThreadId;<BR>begin<BR>   finished:=0;<BR>   i := 65536;<BR>   for i:=1 to threadcount do<BR>     BeginThread(nil, i, @f, Pointer(i), 1, t);<BR>   while finished<threadcount do ;<BR>   Writeln(finished);<BR>end.<BR><BR><BR><BR></P><br><br><iframe name=mail001 marginwidth=0 marginheight=0 src="http://news.21cn.com/shtml.21cn.com/2007/11/13/mail_bottom.html" width=90% scrolling=no height=50 designtimesp="1840" frameborder="0"></iframe>