[F-Script-talk] Block as NSThread target
Brought to you by:
pmougin
From: Joerg G. <jg...@cs...> - 2003-08-07 15:04:59
|
Hi, what is the right way to make a new thread with an FScript block as target? The problem with NSThread detachNewThreadSelector:#value: toTarget:myBlock withObject:someObject. is that there is no NSAutoreleasePool in Place for the execution of myBlock. So myBlock must be shielded by some initialization: NSThread detachNewThreadSelector:#value: toTarget:(makeThreadableBlock value:myBlock) withObject:someObject. Is there a really good implementation in FScript for this? makeThreadableBlock:=[:innerBlock | [:arg ||p| p:=NSAutoreleasePool alloc init. innerBlock value:arg. p release. ]]. yields an error, because NSAutoreleasePools may not be retained (by assignment to p). So no assignment? But how to empty the pool then? makeThreadableBlock:=[:innerBlock | [:arg ||p| NSAutoreleasePool alloc init. innerBlock value:arg. ]]. but even the following does not catch all of the autoreleases (see console warnings) makeThreadableBlock:=[:innerBlock | [:arg ||p| p:=NSValue valueWithNonretainedObject:(NSAutoreleasePool alloc 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 |