Re: [F-Script-talk] NSThreads and F-Script
Brought to you by:
pmougin
From: Ken F. <ken...@gm...> - 2006-09-09 20:54:18
|
On 9/8/06, Jeremy Sacket <js...@ga...> wrote: > > Is it possible > use (void)detachNewThreadSelector:(SEL)aSelector > toTarget:(id)aTarget withObject:(id)anArgument > inside a block and call another block that is defined. > > I.E something like... > > Thread:=[ > Do this in another tread."" > pool := ((NSAutoreleasePool alloc) init). > ...... > [pool release]. > > ]. > > NSThread detachNewThreadSelector:#thread toTarget:self > withObject:null. Not quite like that.. First, pool := NSAutoreleasePool alloc init is similar to this Objective-C code: [aDictionary setObject:(NSAutoreleasePool alloc init) forKey:@"pool"] When you bind the pool to the identifier p, the pool will receive a retain message. An autorelease pool will throw an exception if you try to retain it. You here's what the release notes have to say: "Note that you should not share workspaces or block environments between multiple threads. If you need to execute multiple chunks of F-Script code concurrently, you should use a different FSInterpreter instance for each one." If you detach a thread to a local block like that, you're sharing a single workspace between multiple threads. FScript isn't thread safe in that way. Also, pool := NSAutoreleasePool alloc init is similar to this Objective-C code: [aDictionary setObject:(NSAutoreleasePool alloc init) forKey:@"pool"] When you bind the pool to the identifier p, the pool will receive a retain message. An autorelease pool will throw an exception if you try to retain it. You could work around this by using an NSValue (wrappedPool := NSValue valueWithNonretainedObject:(NSAutoreleasePool alloc init)) |