[fpc-pascal] Where is IsMultiThreaded set under Linux?

Jonas Maebe jonas.maebe at elis.ugent.be
Fri Oct 8 15:46:31 CEST 2010


On 08 Oct 2010, at 15:26, Graeme Geldenhuys wrote:

> On 8 October 2010 15:13, Jonas Maebe <jonas.maebe at elis.ugent.be>  
> wrote:
>>
>> The timeout parameter is ignored when using cthreads, because the  
>> pthreads
>> API does not support waiting for a thread termination with a timeout.
>
>
> So what does Qt do different, so they have a wait option.  From there
> docs it doesn't explicitly mention your application will be frozen
> until the thread terminates. They also support a timeout, so it must
> be possible in FPC too?
>
>  http://doc.trolltech.com/4.7/qthread.html#wait

As Marco mentioned, it can probably be implemented by wrapping the  
entire thread in something that sets an rtlevent when it's finished.  
That would require quite a few changes to cthreads though, and I'm  
personally not convinced it's worth the trouble. If someone wants to  
submit a patch for that however, be my guest.

> See, currently it's a double whammy under Linux. WaitFor (under unix)
> has an infinite timeout, yet timout is not implemented,

I don't understand what you mean by "yet timeout is not implemented".  
WaitFor() on all platforms has an infinte timeout. Maybe Windows'  
messaging system keeps running in the background while your main  
thread is blocked, but that is unrelated to any kinds of timeouts.  
WaitFor() by definition blocks the current thread of execution until  
the thread you are waiting for has finished.

> so as soon as
> you call TThread.WaitFor (in any GUI app: fpGUI, MSEgui, LCL-GTK2
> etc.), you can just as well go kill your process, because it never
> returns.

It will return when the thread you are waiting for is finished, and  
that's the same on all platforms. If the thread does not finish, it  
should not return on any platform. E.g., this is part of the Windows  
code for WaitFor():

     WaitForSingleObject(ulong(FHandle), INFINITE);

Another thing to keep in mind is that you cannot safely WaitFor() a  
thread that has FreeOnTerminate=true. If you want to wait for a  
thread, make sure that property remains false (which is the default).


Jonas



More information about the fpc-pascal mailing list