• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: alloc init thread safe?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Prev by Date: Enum advice please (resend not sure if it was delivered ?)
  • Next by Date: Re: Determining width of a cell in an NSOutlineView
  • Previous by thread: Re: Enum advice please (resend not sure if it was delivered ?)
  • Next by thread: Re: Determining width of a cell in an NSOutlineView
  • Index(es):
    • Date
    • Thread