On Sun, 6 Nov 2005, Tony Pelton wrote:

> On 11/5/05, Michael Van Canneyt <[EMAIL PROTECTED]> wrote:
> >
> > On linux, be sure to include the 'cthreads' as the first unit in your 
> > program's uses clause
> > if you want to use threads. This will install the C thread manager.
> >
> > Note that X is NOT multithreaded, so you must synchronize all output with 
> > the main thread.
> >
> 
> i'm a little curious, so i wanted to follow up.
> 
> as i'm sure most of us know, threading is really not about whether you
> can spin a thread or not.
> 
> the hard work in threading is of course to make sure that your own
> code, and more importantly, all of the runtime code your are linking
> with is thread safe.
> 
> so Michael, your comment about X is meant to convey the fact that the
> UI subsystem on Linux, namely X and all of the subsystems in contains,
> are not thread safe ?

Yes. 
Only 1 thread can access X. The same is true in Windows, BTW.

> 
> are all _other_ units in the FPC and Lazarus runtime known to be
> thread safe (barring bugs of course) ?

The system unit is threadsafe, and so is classes/sysutils.
You'll have to check this on a unit by unit basis.

> 
> presumably there can be other gotchas with non-thread safe libs ?

Yes.

> 
> i assume the 'c' runtime on linux is pretty safe these days.
> 
> i don't know whether all linux distros compile code with multi threaded flags 
> ?

If libc is thread-safe, there should be no need.

> 
> i use Gentoo, and i think there are packages sometimes that require
> you to specify multi threaded flags, it isn't the default.
> 
> are there any references on threading/cross platform mechanisms for
> writing portable, threaded code ?

No.

> 
> for instance, in Java, there are mechanisms for interacting with the
> UI event dispatching thread, so that you can update/interact with
> widgets in a thread safe fashion, which is i assume what you were
> talking about with X and "coordinating".

Yes.
> 
> are these mutexes/guards going to be platform specific ?

No. 

First, FPC offers a cross-platform thread API. 

Second, If a thread wants to interact with the main thread, it calls 
'Synchronize'.
The main thread calls checksynchronize at regular intervals. 
This is transparant for you.

When writing threads in GUI programs, simply make sure that all screen 
input/output 
is always done in the main thread. That is why you have synchronize: to notify 
the 
main thread that there is something to display.

Michael.

_________________________________________________________________
     To unsubscribe: mail [EMAIL PROTECTED] with
                "unsubscribe" as the Subject
   archives at http://www.lazarus.freepascal.org/mailarchives

Reply via email to