[fpc-devel] Re: Multi threading support
"Vinzent Höfler"
JeLlyFish.software at gmx.net
Thu Jul 31 11:44:18 CEST 2008
-------- Original-Nachricht --------
> Von: Florian Klaempfl <florian at freepascal.org>
>
> Before we discuss endless about useless stuff, I'll make a proposal for
> a first addition: support of the synchronized keyword. It does no more
> than protecting a procedure automatically by a critical section so only
> one thread can enter it. But I want to extend it. First, it can be
> applied also to classes and object:
>
> tmyclass = class(...) synchronized
>
> This means that all classes synchronize against one critical section.
You mean:
1) All classes of the type (and descendants)?
2) Only the methods additionally marked with a "synchronized" statement?
3) Corollary: A critical section is either class wide or instance wide? Meaning: you can't possibly use both approaches at the same time? For instance, having some methods that are synchronized between all instances existing (class wide) _and_ another set of methods only synchronized on the instance?
If so, maybe the syntax below could be extended to specify how the synchronization should be done without the explicit use of another RTLCriticalSection? (Maybe "synchronized class" for the class-wide one, a simple "synchronized" for the instance-wide?)
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... ;)
> Besides saving the typing of endless try ... finally statements and the
> initialiation of the unnamed critical sections, it creates also slightly
> better code because the LeaveCriticalSection call can be inside the
> implicit exception frame which is created anyways.
Hmm. Depends on the code. ;)
> Any suggestions about doing it better?
Warnings, if you use potentially blocking functions inside a synchronized method? ;)
Like:
|procedure My_Thread.Do_Work; synchronized;
|begin
| ...
| Suspend;
|end;
Well, I guess the compiler doesn't know which operations are potentially blocking, does it?
Vinzent.
--
GMX startet ShortView.de. Hier findest Du Leute mit Deinen Interessen!
Jetzt dabei sein: http://www.shortview.de/wasistshortview.php?mc=sv_ext_mf@gmx
More information about the fpc-devel
mailing list