Re: Multithreading and memory management question
Re: Multithreading and memory management question
- Subject: Re: Multithreading and memory management question
- From: eveningnick eveningnick <email@hidden>
- Date: Fri, 22 Apr 2011 01:10:48 +0300
Hi Ken,
> How are you spawning your threads?
> If you use Cocoa methods, then they automatically retain the object which is the target of the selector and the argument object for the life of the thread. So, you may be getting this automatically without realizing it. If not, then it should be easy to arrange.
thanks, i used cocoa methods but didn't know the object is being
retained. That simplifies the code how it looks :)
> If you're using some other technique to spawn your threads, you can just retain the object before spawning the thread and then have the thread work function or method release it before exiting. The retain and the release don't have to occur on the same thread.
The problem i still have - is the display link. It is a system
thread, that calls a method periodically. When i stop display link
(while the method is being executed) - this execution of the method
will be the last, it won't be called anymore. As i described in the
first post, the object is being used from the display link callback. I
can't pass an object that comfortable, as i did with cocoa methods
(unfortunately). I can't retain an object before starting display link
as you suggested here - because i can't know when this "before
exiting" time happens - display link's thread is a CoreVideo
framework's thread, and it just calls my function repeatedly. I was
thinking about using some custom flag (like, BOOL
thisIsTheLastTimeTheDisplayLinkMethodIsBeingCalled) protected by a
critical section, and which is set when i stop "System high-priority
display link thread". But the solution would look very ad-hoc and
hardly readable, hardly maintainable when the amount of code grows. I
am wondering maybe there's a prettier way to do it.
Thanks
_______________________________________________
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