<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Productive Waste of Time: Figuring out the main thread</title>
	<atom:link href="http://www.noodlesoft.com/blog/2007/05/01/productive-waste-of-time-figuring-out-the-main-thread/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.noodlesoft.com/blog/2007/05/01/productive-waste-of-time-figuring-out-the-main-thread/</link>
	<description>On Mac OS X programming</description>
	<lastBuildDate>Thu, 12 Aug 2010 19:25:08 -0400</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.5</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Adrian Bool</title>
		<link>http://www.noodlesoft.com/blog/2007/05/01/productive-waste-of-time-figuring-out-the-main-thread/comment-page-1/#comment-15541</link>
		<dc:creator>Adrian Bool</dc:creator>
		<pubDate>Mon, 31 Mar 2008 17:31:09 +0000</pubDate>
		<guid isPermaLink="false">http://www.noodlesoft.com/blog/2007/05/01/productive-waste-of-time-figuring-out-the-main-thread/#comment-15541</guid>
		<description>If you needed this information in your application, would you not just set a global pointer to it as the app starts up - and you know you are in the main thread - for later use..?  Gets rid of any possible deadlocks...</description>
		<content:encoded><![CDATA[<p>If you needed this information in your application, would you not just set a global pointer to it as the app starts up &#8211; and you know you are in the main thread &#8211; for later use..?  Gets rid of any possible deadlocks&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: JustBill</title>
		<link>http://www.noodlesoft.com/blog/2007/05/01/productive-waste-of-time-figuring-out-the-main-thread/comment-page-1/#comment-7871</link>
		<dc:creator>JustBill</dc:creator>
		<pubDate>Tue, 06 Nov 2007 18:18:08 +0000</pubDate>
		<guid isPermaLink="false">http://www.noodlesoft.com/blog/2007/05/01/productive-waste-of-time-figuring-out-the-main-thread/#comment-7871</guid>
		<description>none of what you are suggesting is necessary at all.  i&#039;m relatively new to the Mac platform, but at least from what i can tell you have everything you need in the leopard release (not sure if it was there before).  

the major reason to run performSelectorOnMainThread is to ensure secondary threads don&#039;t update the UI since thread safe access is accomplish through thread affinity using NSRunLoop.

you can call performSelectorOnMainThread on any object or class, and providing the selector is implemented via a matching method, Cocoa will execute that method on the &quot;main&quot; thread.

whomever is writing the code should be aware what their doing;nonetheless, you can ensure it by doing something similar to the following:

-(void)doSomething: (NSNumber*)someValue
{
   if (![NSThread isMainThread])
      [self performSelectorOnMainThread:@selector(doSomething:)
                                              withObject:somevalue 
                                              waitUntilDone:NO];
   else
      [_txtField1 setIntValue: [someValue intValue]];
}</description>
		<content:encoded><![CDATA[<p>none of what you are suggesting is necessary at all.  i&#8217;m relatively new to the Mac platform, but at least from what i can tell you have everything you need in the leopard release (not sure if it was there before).  </p>
<p>the major reason to run performSelectorOnMainThread is to ensure secondary threads don&#8217;t update the UI since thread safe access is accomplish through thread affinity using NSRunLoop.</p>
<p>you can call performSelectorOnMainThread on any object or class, and providing the selector is implemented via a matching method, Cocoa will execute that method on the &#8220;main&#8221; thread.</p>
<p>whomever is writing the code should be aware what their doing;nonetheless, you can ensure it by doing something similar to the following:</p>
<p>-(void)doSomething: (NSNumber*)someValue<br />
{<br />
   if (![NSThread isMainThread])<br />
      [self performSelectorOnMainThread:@selector(doSomething:)<br />
                                              withObject:somevalue<br />
                                              waitUntilDone:NO];<br />
   else<br />
      [_txtField1 setIntValue: [someValue intValue]];<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Adam Nohejl</title>
		<link>http://www.noodlesoft.com/blog/2007/05/01/productive-waste-of-time-figuring-out-the-main-thread/comment-page-1/#comment-5777</link>
		<dc:creator>Adam Nohejl</dc:creator>
		<pubDate>Sat, 29 Sep 2007 19:13:12 +0000</pubDate>
		<guid isPermaLink="false">http://www.noodlesoft.com/blog/2007/05/01/productive-waste-of-time-figuring-out-the-main-thread/#comment-5777</guid>
		<description>Suppose that the main thread is busy (it doesn&#039;t cycle through its run loop for the moment) - then the +mainThread method gets blocked waiting. Suppose that, for some reason, the main thread will want to stay like this until some work is done in the detached thread (there may be for instance a lock it wants to acquire), but the detached thread is now blocked waiting for a selector to be executed on the main thread...

Just a hypothetical scenario, but anyway, I don&#039;t think this way of determining the main thread is a good idea. I would either use a different method or set the main thread static var beforehand (not very elegant).</description>
		<content:encoded><![CDATA[<p>Suppose that the main thread is busy (it doesn&#8217;t cycle through its run loop for the moment) &#8211; then the +mainThread method gets blocked waiting. Suppose that, for some reason, the main thread will want to stay like this until some work is done in the detached thread (there may be for instance a lock it wants to acquire), but the detached thread is now blocked waiting for a selector to be executed on the main thread&#8230;</p>
<p>Just a hypothetical scenario, but anyway, I don&#8217;t think this way of determining the main thread is a good idea. I would either use a different method or set the main thread static var beforehand (not very elegant).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ofri Wolfus</title>
		<link>http://www.noodlesoft.com/blog/2007/05/01/productive-waste-of-time-figuring-out-the-main-thread/comment-page-1/#comment-3874</link>
		<dc:creator>Ofri Wolfus</dc:creator>
		<pubDate>Wed, 18 Jul 2007 11:33:53 +0000</pubDate>
		<guid isPermaLink="false">http://www.noodlesoft.com/blog/2007/05/01/productive-waste-of-time-figuring-out-the-main-thread/#comment-3874</guid>
		<description>Just for fun, here is another approach which doesn&#039;t block the caller thread (yes, I know I&#039;m leaking the main thread instance but it shouldn&#039;t go away anyhow)
&lt;code&gt;static NSThread *_mainThread = nil;

static __attribute__((constructor)) void _DPInitMainThread(void) {
	_mainThread = [[NSThread currentThread] retain];
}

+ (NSThread *)mainThread {
	return _mainThread;
}&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>Just for fun, here is another approach which doesn&#8217;t block the caller thread (yes, I know I&#8217;m leaking the main thread instance but it shouldn&#8217;t go away anyhow)<br />
<code>static NSThread *_mainThread = nil;</p>
<p>static __attribute__((constructor)) void _DPInitMainThread(void) {<br />
	_mainThread = [[NSThread currentThread] retain];<br />
}</p>
<p>+ (NSThread *)mainThread {<br />
	return _mainThread;<br />
}</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Martin Wennerberg</title>
		<link>http://www.noodlesoft.com/blog/2007/05/01/productive-waste-of-time-figuring-out-the-main-thread/comment-page-1/#comment-2135</link>
		<dc:creator>Martin Wennerberg</dc:creator>
		<pubDate>Tue, 08 May 2007 06:48:31 +0000</pubDate>
		<guid isPermaLink="false">http://www.noodlesoft.com/blog/2007/05/01/productive-waste-of-time-figuring-out-the-main-thread/#comment-2135</guid>
		<description>Method names starting with _ are reserved for Apple private use so I would suggest renaming the _setMainThread method to make sure that you aren&#039;t overriding something in Apple&#039;s implementation on NSThread. (http://developer.apple.com/documentation/Cocoa/Conceptual/ObjectiveC/Articles/chapter_950_section_11.html)

Also, as Apple might implement methods called -isMainThread and +mainThread in future versions of Mac OS X I would call them something that Apple wouldn&#039;t.</description>
		<content:encoded><![CDATA[<p>Method names starting with _ are reserved for Apple private use so I would suggest renaming the _setMainThread method to make sure that you aren&#8217;t overriding something in Apple&#8217;s implementation on NSThread. (<a href="http://developer.apple.com/documentation/Cocoa/Conceptual/ObjectiveC/Articles/chapter_950_section_11.html" rel="nofollow">http://developer.apple.com/documentation/Cocoa/Conceptual/ObjectiveC/Articles/chapter_950_section_11.html</a>)</p>
<p>Also, as Apple might implement methods called -isMainThread and +mainThread in future versions of Mac OS X I would call them something that Apple wouldn&#8217;t.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jesper</title>
		<link>http://www.noodlesoft.com/blog/2007/05/01/productive-waste-of-time-figuring-out-the-main-thread/comment-page-1/#comment-2065</link>
		<dc:creator>Jesper</dc:creator>
		<pubDate>Sun, 06 May 2007 09:05:14 +0000</pubDate>
		<guid isPermaLink="false">http://www.noodlesoft.com/blog/2007/05/01/productive-waste-of-time-figuring-out-the-main-thread/#comment-2065</guid>
		<description>Convincing.</description>
		<content:encoded><![CDATA[<p>Convincing.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mr_noodle</title>
		<link>http://www.noodlesoft.com/blog/2007/05/01/productive-waste-of-time-figuring-out-the-main-thread/comment-page-1/#comment-1952</link>
		<dc:creator>mr_noodle</dc:creator>
		<pubDate>Tue, 01 May 2007 16:14:12 +0000</pubDate>
		<guid isPermaLink="false">http://www.noodlesoft.com/blog/2007/05/01/productive-waste-of-time-figuring-out-the-main-thread/#comment-1952</guid>
		<description>Yes, I know of what you speak, which is, of course, of NOTHING, because there is NOTHING being divulged about future OS releases that may or may not exist. Nothing to see here. La-di-da. Oh, look over there!</description>
		<content:encoded><![CDATA[<p>Yes, I know of what you speak, which is, of course, of NOTHING, because there is NOTHING being divulged about future OS releases that may or may not exist. Nothing to see here. La-di-da. Oh, look over there!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chris Ryland</title>
		<link>http://www.noodlesoft.com/blog/2007/05/01/productive-waste-of-time-figuring-out-the-main-thread/comment-page-1/#comment-1951</link>
		<dc:creator>Chris Ryland</dc:creator>
		<pubDate>Tue, 01 May 2007 16:04:08 +0000</pubDate>
		<guid isPermaLink="false">http://www.noodlesoft.com/blog/2007/05/01/productive-waste-of-time-figuring-out-the-main-thread/#comment-1951</guid>
		<description>Luckily, I believe this code, along with many other good thread-related activities, will no longer be an issue in a few momths. Ahem. ;-)</description>
		<content:encoded><![CDATA[<p>Luckily, I believe this code, along with many other good thread-related activities, will no longer be an issue in a few momths. Ahem. <img src='http://www.noodlesoft.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
</channel>
</rss>
