[fpc-devel] Re: Multi threading support

tom_at_work tom_at_work at gmx.at
Thu Jul 31 12:53:56 CEST 2008


Hello,

Am 31.07.2008 um 11:56 schrieb Florian Klaempfl:

> Vinzent Höfler schrieb:
>> -------- Original-Nachricht -------
>> OTOH, it's looks about the same as in Java and even Java now has
>> explicit Locks, because "synchronized" simply isn't efficient nor
>> flexible enough... ;)
>
> Since I don't use java, what's the difference to locks?
>

In practice imo not too much, synchronized is just a convenience  
functionality, exactly like the one you proposed.

In short the difference:

Java always locks on monitors i.e. guards which are available for any  
object; Pre 1.5 the only way to lock was using some syntax additions.  
The syntax allows per method (class or instance) or per block scope,  
i.e.

synchronized void doSomething() { ... } // method level: monitor  
object is either "this" or this.class object

void doSomething() {
    ...
    synchronized (monitor) { // on block level; monitor object is  
"this" if not specified otherwise the given object
    }
    ...
}

With 1.5 they added a "Lock" interface which provides the usual lock 
()/trylock()/unlock() methods which should be self-explaining.
This for example allows interlocked locks if required

lock1.lock();
...
lock2.lock();
...
lock1.unlock();
...
lock2.unlock();


Hth,
   Thomas


More information about the fpc-devel mailing list