Re: alloc init thread safe?
Re: alloc init thread safe?
- Subject: Re: alloc init thread safe?
- From: John Love <email@hidden>
- Date: Mon, 5 Jan 2009 07:26:57 -0500
This request focuses on an old cocoabuilder thread:
http://www.cocoabuilder.com/archive/message/cocoa/2007/3/8/179989
David writes:
>>>
But now I find I have a BOOL method that is rarely and randomly
returning NO when the only exit to the method is "return YES;" so I
have some strange problem somewhere. It turned out that the method
didn't need to be BOOL, but the result is checked anyway.
>>>
I do have an INT in the form of an ENUMerated constant, instead of his
BOOL. And for sure, I have not yet discovered my version of "some
strange problem somewhere".
typedef int myStatus;
enum {
kNoError,
kConstant1,
kConstant2,
kWhoops
};
- (myStatus) myRoutine {
if ([self myOtherRoutine] == kNoError) {
// calculations here
if (something) return kConstant1;
else return kConstant2;
}
else {
return kWhoops;
}
}
Even when [self myOtherRoutine] does *not* return kNoError, myRoutine
says it does.
Let me wrap this up by saying when myRoutine is called in my main
thread, everything works fine .. but when called by a second thread
(via [NSThread detachNewThreadSelector:toTarget:withObject:] it
definitely does not work.
An interesting side note is that if I insert the following as the very
1st line in myRoutine:
return [self myOtherRoutine];
it works in the second thread. If this sounds "crazy" you are
definitely correct. Once again, "some strange problem somewhere".
Thanks for listening.
John Love
Touch the Future! Teach!
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden