Re: [F-Script-talk] Block as NSThread target
Brought to you by:
pmougin
From: Philippe M. <pm...@ac...> - 2003-08-07 20:19:54
|
Hi Joerg, As you suggested, it would probably requires providing a specific=20 Objective-C method for block evaluation managing the creation and=20 destruction of the an autorelease pool (it would be easy too add it=20 yourself, for instance in a category). However, you should completely=20 ignore the problem for now, because of a much bigger issue: in the=20 current implementation, the F-Script run-time is not thread safe. That=20= is, two threads in the same task should not access the F-Script=20 run-time concurrently; something which will happen in your case since=20 you're detaching a thread executing an F-Script block from an F-Script=20= program. Can you, by chance, re-formulate your application with a single active=20= F-Script thread ? Best, Phil Le jeudi, 7 ao=FB 2003, =E0 17:02 Europe/Paris, Joerg Garbers a =E9crit = : > Hi, > what is the right way to make a new thread with an FScript block as=20 > target? > > The problem with > NSThread detachNewThreadSelector:#value: toTarget:myBlock=20 > withObject:someObject. > is that there is no NSAutoreleasePool in Place for the execution of=20 > myBlock. > > So myBlock must be shielded by some initialization: > NSThread detachNewThreadSelector:#value: toTarget:(makeThreadableBlock=20= > value:myBlock) withObject:someObject. > > Is there a really good implementation in FScript for this? > > makeThreadableBlock:=3D[:innerBlock | > [:arg ||p| > p:=3DNSAutoreleasePool alloc init. > innerBlock value:arg. > p release. > ]]. > > yields an error, because NSAutoreleasePools may not be retained (by=20 > assignment to p). So no assignment? But how to empty the pool then? > > makeThreadableBlock:=3D[:innerBlock | > [:arg ||p| > NSAutoreleasePool alloc init. > innerBlock value:arg. > ]]. > > but even the following does not catch all of the autoreleases (see=20 > console warnings) > > makeThreadableBlock:=3D[:innerBlock | > [:arg ||p| > p:=3DNSValue valueWithNonretainedObject:(NSAutoreleasePool alloc=20= > init). > innerBlock value:arg. > p nonretainedObjectValue release. > ]]. > > Any other solutions? Or should the Block method > -(id) valueArgs:(id*)args count:(unsigned)count > contain NSAutoreleasePool initialization and termination? > > Joerg > |