<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-6515147997242787617</id><updated>2012-02-16T19:50:23.679-08:00</updated><category term='c#'/><category term='Computers'/><category term='jit'/><category term='Javascript'/><category term='programming'/><title type='text'>Yogi's Post</title><subtitle type='html'>Mumbling about programming, the web and everything in between.</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://eylonyogev.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6515147997242787617/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://eylonyogev.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Eylon Yogev</name><uri>http://www.blogger.com/profile/09748464292766314155</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://3.bp.blogspot.com/_sMu4s8uus94/SMmNcXyaijI/AAAAAAAAA5Y/R48AFTXYQp8/S220/n509798273_4395.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>5</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-6515147997242787617.post-7707584448290684119</id><published>2009-04-25T23:17:00.000-07:00</published><updated>2009-04-26T09:55:09.023-07:00</updated><title type='text'>AutoLaunch - A new Firefox addon</title><content type='html'>&lt;div&gt;&lt;div&gt;Although I'm a &lt;a href="http://www.firefox.com/"&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;Firefox &lt;/span&gt;&lt;/a&gt;fan, after using &lt;span class="Apple-style-span" style="font-style: italic; "&gt;&lt;a href="http://www.google.com/chrome"&gt;Google Chrome&lt;/a&gt;&lt;/span&gt; for some time now I can say with confidence that although it's a simple browser it has some unique features that make it a &lt;span class="Apple-style-span" style="font-weight: bold; "&gt;great browser too&lt;/span&gt;. &lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;span class="Apple-style-span" style="font-size: large;"&gt;What I like about Chrome&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;One cool feature I like in Chrome is the ability to click on a downloading file, making it automatically launch when the download has completed. &lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;span class="Apple-style-span" style="font-size: large;"&gt;A Firefox addon is born&lt;/span&gt;&lt;/span&gt; &lt;/div&gt;&lt;div&gt;One of Firefox's most endearing features, as far as i'm concerned, is that I can just change about anything I want with a few lines of JavaScript. The lack of an autolaunch feature seemed like a great opportunity to take advantage of this capability so I spent some time last weekend developing my own version of Chrome's auto-launch feature for Firefox and so &lt;a href="https://addons.mozilla.org/en-US/firefox/addon/11574"&gt;AutoLaunch&lt;/a&gt; was born.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-size: large;"&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;What does AutoLaunch do?&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;With&lt;a href="https://addons.mozilla.org/en-US/firefox/addon/11574"&gt; AutoLaunch&lt;/a&gt; installed you can double click any file, even while downloading, and it will launch once the download is completed. It might not seem like much but I like it and I'm letting you enjoy it for free... &lt;/div&gt;&lt;div&gt;; )&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;img src="http://3.bp.blogspot.com/_sMu4s8uus94/SfQCJde7WiI/AAAAAAAABXI/_XNXrtNEGBU/s320/AutoLaunch.PNG" style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;width: 320px; height: 146px;" border="0" alt="" id="BLOGGER_PHOTO_ID_5328886620642564642" /&gt;&lt;div style="text-align: center;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: center;"&gt;Download it from here: &lt;a href="https://addons.mozilla.org/en-US/firefox/addon/11574"&gt;https://addons.mozilla.org/en-US/firefox/addon/11574&lt;/a&gt;&lt;/div&gt;&lt;div style="text-align: center;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div style="text-align: center;"&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;span class="Apple-style-span" style="font-size: large;"&gt;Why I like it?&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;My little addon enables me to launch files from the web with a single click, just as if they'd been stored locally on my computer saving me time, aggravation and unnecessary clicks. &lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-size: large;"&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;Before we part...&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;I believe that as we move our digital world online and "The Cloud" becomes the repository we use to encase our lives and souls we must guarantee that we retain the same comfort and accessibility we have in these dreary desktop days. Sometimes it's all about taking care of little details - like double clicking a filename and having it launch...&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6515147997242787617-7707584448290684119?l=eylonyogev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://eylonyogev.blogspot.com/feeds/7707584448290684119/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6515147997242787617&amp;postID=7707584448290684119' title='43 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6515147997242787617/posts/default/7707584448290684119'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6515147997242787617/posts/default/7707584448290684119'/><link rel='alternate' type='text/html' href='http://eylonyogev.blogspot.com/2009/04/autolaunch-new-firefox-addon.html' title='AutoLaunch - A new Firefox addon'/><author><name>Eylon Yogev</name><uri>http://www.blogger.com/profile/09748464292766314155</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://3.bp.blogspot.com/_sMu4s8uus94/SMmNcXyaijI/AAAAAAAAA5Y/R48AFTXYQp8/S220/n509798273_4395.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/_sMu4s8uus94/SfQCJde7WiI/AAAAAAAABXI/_XNXrtNEGBU/s72-c/AutoLaunch.PNG' height='72' width='72'/><thr:total>43</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6515147997242787617.post-7773624412148562638</id><published>2009-02-12T15:04:00.000-08:00</published><updated>2009-02-12T15:06:29.561-08:00</updated><title type='text'></title><content type='html'>&lt;span class="Apple-style-span"   style="  ;font-family:Verdana;font-size:13px;"&gt;&lt;h2   style="  color: rgb(255, 153, 0); font-weight: bold; font-family:Verdana, Helvetica, Arial, sans-serif;font-size:13pt;"&gt;&lt;span class="Apple-style-span"  style="color: rgb(0, 0, 0);  font-weight: normal; font-size:11px;"&gt;&lt;h1    style="   font-weight: bold; margin-top: 0px; margin-bottom: 0px; padding-bottom: 0px; font-family:Verdana, Helvetica, Arial, sans-serif;font-size:16pt;color:black;"&gt;&lt;span id="ctl00_ArticleTopHeader_ArticleTitle" class="ArticleTopTitle"&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt;How to determine the processor count from a Silverlight web page&lt;/span&gt;&lt;/span&gt;&lt;/h1&gt;&lt;b&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt;By &lt;/span&gt;&lt;a href="http://www.codeproject.com/script/Articles/MemberArticles.aspx?amid=4154298" style="text-decoration: none; "&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt;Eylon Yogev.&lt;/span&gt;&lt;/a&gt;&lt;/b&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt;&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span id="ctl00_ArticleTopHeader_ArticleDescr" class="ArticleTopDescr"&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt;How can you tell if a computer has more than one CPU without using any special permissions.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/h2&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt;&lt;img height="131" src="http://www.codeproject.com/KB/silverlight/multicore/onlyone.PNG" width="425" /&gt;&lt;/span&gt;&lt;/div&gt;&lt;h2 style="font-family: Verdana, Helvetica, Arial, sans-serif; font-size: 13pt; font-weight: bold; "&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt;Parallel programming requires an easy way to tell if a user has multiple CPUs&lt;/span&gt;&lt;/h2&gt;&lt;p    style="font-family:Verdana, Helvetica, Arial, sans-serif;font-size:10pt;color:black;"&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt;Now that most new computes have multiple processors, we are seeing a rapid rise in the usage of parallel programming. Many libraries already supply efficient code for computers with multiple core processors, but how can you tell if the computer you are running on indeed has more than one CPU?&lt;/span&gt;&lt;/p&gt;&lt;h2 style="font-family: Verdana, Helvetica, Arial, sans-serif; font-size: 13pt; font-weight: bold; "&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt;Why is the need to identify multiple CPUs becoming a pressing issue now?&lt;/span&gt;&lt;/h2&gt;&lt;p style="font-family: Verdana, Helvetica, Arial, sans-serif; font-size: 10pt; "&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt;Most programs today are multithreaded. More and more libraries are written for effective multithreaded code, with the assumption that this code will be run on computers with multiple cores. The need to know whether the computer is multi-core is a must, but in certain cases, like web applications for instance, you can’t “ask” the Operating System how many cores it is using outright.&lt;/span&gt;&lt;/p&gt;&lt;h2 style="font-family: Verdana, Helvetica, Arial, sans-serif; font-size: 13pt; font-weight: bold; "&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt;How is this solved “normally”?&lt;/span&gt;&lt;/h2&gt;&lt;p style="font-family: Verdana, Helvetica, Arial, sans-serif; font-size: 10pt; "&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt;When running in the .NET environment, you can easily get the exact number of processors by using the following:&lt;/span&gt;&lt;/p&gt;&lt;div id="premain0" class="SmallText" style="font-size: 8pt; width: 1083px; cursor: pointer; "&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt;&lt;img id="preimg0" src="http://www.codeproject.com/images/minus.gif" height="9" width="9" preid="0" /&gt;&lt;/span&gt;&lt;span id="precollapse0" preid="0" style="margin-bottom: 0px; "&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt; Collapse&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;pre lang="cs" id="pre0" style="background-color: rgb(251, 237, 187); padding-top: 7pt; padding-right: 7pt; padding-bottom: 7pt; padding-left: 7pt; font: normal normal normal 9pt/normal 'Courier New', Courier, mono; white-space: pre; overflow-x: auto !important; overflow-y: auto !important; margin-top: 0px; "&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt;System.Environment.ProcessorCount;&lt;/span&gt;&lt;/pre&gt;&lt;p style="font-family: Verdana, Helvetica, Arial, sans-serif; font-size: 10pt; "&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt;The bad news is that this property isn’t available for situations where you don’t have permission to ask the Operating System about the number of processors the system is running. This is exactly the situation you are in when you are developing web pages and RIAs based on MS Silverlight or Adobe Flash.&lt;/span&gt;&lt;/p&gt;&lt;h2 style="font-family: Verdana, Helvetica, Arial, sans-serif; font-size: 13pt; font-weight: bold; "&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt;So what to do?&lt;/span&gt;&lt;/h2&gt;&lt;p style="font-family: Verdana, Helvetica, Arial, sans-serif; font-size: 10pt; "&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt;I wrote the following code for determining whether a machine is a multi-core using only the basic operations available in any language and on any platform. The code runs two threads in parallel, and checks if they can really run at the same time.&lt;/span&gt;&lt;/p&gt;&lt;p style="font-family: Verdana, Helvetica, Arial, sans-serif; font-size: 10pt; "&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt;The main key is to use &lt;/span&gt;&lt;code style="font-family: 'Courier New', Courier, mono; font-size: 11pt; "&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt;SpinWait&lt;/span&gt;&lt;/code&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt;, and although it’s a lot of fun, unfortunately it isn’t deterministic…&lt;/span&gt;&lt;/p&gt;&lt;h2 style="font-family: Verdana, Helvetica, Arial, sans-serif; font-size: 13pt; font-weight: bold; "&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt;SpinWait - The magic key&lt;/span&gt;&lt;/h2&gt;&lt;p style="font-family: Verdana, Helvetica, Arial, sans-serif; font-size: 10pt; "&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt;Roughly defined, a thread’s ‘Quanta’ is the minimum time that the Operating System will dedicate to the thread without making a context switch. It’s usually somewhere between 10 and 15 milliseconds. The code I wrote keeps the processors busy for the amount of instructions given, like creating an empty loop with an increased index; however, unlike ‘&lt;/span&gt;&lt;code style="font-family: 'Courier New', Courier, mono; font-size: 11pt; "&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt;Sleep&lt;/span&gt;&lt;/code&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt;’, this code prevents context switching from the thread, unless it spins in excess of the thread’s quanta.&lt;/span&gt;&lt;/p&gt;&lt;p style="font-family: Verdana, Helvetica, Arial, sans-serif; font-size: 10pt; "&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt;Note that the OS could demand a context switch due to a system interrupt, or for some other reasons, in which case, the code might report that the computer has more than one core, despite the fact that there is only one core.&lt;/span&gt;&lt;/p&gt;&lt;p style="font-family: Verdana, Helvetica, Arial, sans-serif; font-size: 10pt; "&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt;Here is the code I use:&lt;/span&gt;&lt;/p&gt;&lt;div id="premain1" class="SmallText" style="font-size: 8pt; width: 1083px; cursor: pointer; "&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt;&lt;img id="preimg1" src="http://www.codeproject.com/images/minus.gif" height="9" width="9" preid="1" /&gt;&lt;/span&gt;&lt;span id="precollapse1" preid="1" style="margin-bottom: 0px; "&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt; Collapse&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;pre lang="cs" id="pre1" style="background-color: rgb(251, 237, 187); padding-top: 7pt; padding-right: 7pt; padding-bottom: 7pt; padding-left: 7pt; font: normal normal normal 9pt/normal 'Courier New', Courier, mono; white-space: pre; overflow-x: auto !important; overflow-y: auto !important; margin-top: 0px; "&gt;&lt;span class="code-comment" style="font-style: italic; "&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt;//&lt;/span&gt;&lt;/span&gt;&lt;span class="code-comment" style="font-style: italic; "&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt; will indicate that the computer has more than one processor&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt; &lt;/span&gt;&lt;span class="code-keyword"&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt;bool&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt; moreThanOne = &lt;/span&gt;&lt;span class="code-keyword"&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt;false&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt;; &lt;/span&gt;&lt;span class="code-comment" style="font-style: italic; "&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt;//&lt;/span&gt;&lt;/span&gt;&lt;span class="code-comment" style="font-style: italic; "&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt; will close the other thread eventually&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt; &lt;/span&gt;&lt;span class="code-keyword"&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt;bool&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt; toContinue = &lt;/span&gt;&lt;span class="code-keyword"&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt;true&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt;; ManualResetEvent m = &lt;/span&gt;&lt;span class="code-keyword"&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt;new&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt; ManualResetEvent(&lt;/span&gt;&lt;span class="code-keyword"&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt;false&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt;); &lt;/span&gt;&lt;span class="code-comment" style="font-style: italic; "&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt;//&lt;/span&gt;&lt;/span&gt;&lt;span class="code-comment" style="font-style: italic; "&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt; open the secondary thread&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt; Thread t = &lt;/span&gt;&lt;span class="code-keyword"&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt;new&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt; Thread(&lt;/span&gt;&lt;span class="code-keyword"&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt;new&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt; ThreadStart(&lt;/span&gt;&lt;span class="code-keyword"&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt;delegate&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt; {     &lt;/span&gt;&lt;span class="code-comment" style="font-style: italic; "&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt;//&lt;/span&gt;&lt;/span&gt;&lt;span class="code-comment" style="font-style: italic; "&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt; make sure it has time to start&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt;     m.Set();     &lt;/span&gt;&lt;span class="code-comment" style="font-style: italic; "&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt;//&lt;/span&gt;&lt;/span&gt;&lt;span class="code-comment" style="font-style: italic; "&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt; set the flag while not signaled to stop&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt;     &lt;/span&gt;&lt;span class="code-keyword"&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt;while&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt; (toContinue)         moreThanOne = &lt;/span&gt;&lt;span class="code-keyword"&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt;true&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt;; })); t.IsBackground = &lt;/span&gt;&lt;span class="code-keyword"&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt;false&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt;; t.Start(); &lt;/span&gt;&lt;span class="code-comment" style="font-style: italic; "&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt;//&lt;/span&gt;&lt;/span&gt;&lt;span class="code-comment" style="font-style: italic; "&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt; waiting for the thread to start&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt; m.WaitOne(); &lt;/span&gt;&lt;span class="code-comment" style="font-style: italic; "&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt;//&lt;/span&gt;&lt;/span&gt;&lt;span class="code-comment" style="font-style: italic; "&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt; forcing context switch&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt; Thread.Sleep(&lt;/span&gt;&lt;span class="code-digit"&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt;0&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt;); &lt;/span&gt;&lt;span class="code-comment" style="font-style: italic; "&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt;//&lt;/span&gt;&lt;/span&gt;&lt;span class="code-comment" style="font-style: italic; "&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt; begining of the threads quanta&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt; moreThanOne = &lt;/span&gt;&lt;span class="code-keyword"&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt;false&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt;; &lt;/span&gt;&lt;span class="code-comment" style="font-style: italic; "&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt;//&lt;/span&gt;&lt;/span&gt;&lt;span class="code-comment" style="font-style: italic; "&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt; spin for a short time. Enough for the other thread to set the flag&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt; &lt;/span&gt;&lt;span class="code-comment" style="font-style: italic; "&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt;//&lt;/span&gt;&lt;/span&gt;&lt;span class="code-comment" style="font-style: italic; "&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt; but still shorter than the quanta&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt; Thread.SpinWait(&lt;/span&gt;&lt;span class="code-digit"&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt;100000&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt;); &lt;/span&gt;&lt;span class="code-comment" style="font-style: italic; "&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt;//&lt;/span&gt;&lt;/span&gt;&lt;span class="code-comment" style="font-style: italic; "&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt; stop the secondary thread&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt; toContinue = &lt;/span&gt;&lt;span class="code-keyword"&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt;false&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt;; &lt;/span&gt;&lt;span class="code-comment" style="font-style: italic; "&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt;//&lt;/span&gt;&lt;/span&gt;&lt;span class="code-comment" style="font-style: italic; "&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt; return the result&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt; &lt;/span&gt;&lt;span class="code-keyword"&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt;return&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt; moreThanOne;&lt;/span&gt;&lt;/pre&gt;&lt;p style="font-family: Verdana, Helvetica, Arial, sans-serif; font-size: 10pt; "&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt;The code opens a thread dedicated to repeatedly setting a boolean flag, with the idea of having this thread run on a secondary core, if one exists. In order to ensure that the thread has started and is ready to loop, a ‘wait’ handle is used. The main thread waits for the secondary thread to start, and then calls ‘&lt;/span&gt;&lt;code   style="font-family:'Courier New', Courier, mono;font-size:11pt;"&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt;Thread.Sleep(&lt;/span&gt;&lt;span class="code-digit"&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt;0&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt;)&lt;/span&gt;&lt;/code&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt;’ to force the context switch. This ensures the next instruction will execute at the beginning of the thread’s quanta. In order to allow the other thread to set the flag on the other core while we are still spinning, we ‘&lt;/span&gt;&lt;code style="font-family: 'Courier New', Courier, mono; font-size: 11pt; "&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt;SpinWait&lt;/span&gt;&lt;/code&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt;’ 100000 instructions. Since the ‘&lt;/span&gt;&lt;code style="font-family: 'Courier New', Courier, mono; font-size: 11pt; "&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt;SpinWait&lt;/span&gt;&lt;/code&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt;’ is shorter than the thread’s quanta, it won’t force a context switch. Now, we can examine our outcome: If the flag has been set during the elapsed time, we know it must have been set by another processor that processed the thread while the other process was busy spinning.&lt;/span&gt;&lt;/p&gt;&lt;h2 style="font-family: Verdana, Helvetica, Arial, sans-serif; font-size: 13pt; font-weight: bold; "&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt;Implementation and usage&lt;/span&gt;&lt;/h2&gt;&lt;p style="font-family: Verdana, Helvetica, Arial, sans-serif; font-size: 10pt; "&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt;I developed the code presented above while I was researching the performance of our &lt;/span&gt;&lt;a href="http://www.headup.com/" style="text-decoration: none; "&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt;http://www.headup.com&lt;/span&gt;&lt;/a&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt; application. I had discovered we were wasting a lot of time on mandatory locks that, although required, didn’t justify the accrued overhead.&lt;/span&gt;&lt;/p&gt;&lt;h2 style="font-family: Verdana, Helvetica, Arial, sans-serif; font-size: 13pt; font-weight: bold; "&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt;Spinlock – good value, low cost&lt;/span&gt;&lt;/h2&gt;&lt;p style="font-family: Verdana, Helvetica, Arial, sans-serif; font-size: 10pt; "&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt;After some research, I decided to use the ‘SpinLock’ implementation, which utilizes the computer’s two cores to make an efficient lock, in order to boost our application’s performance at, what turned out to be, a very low effort. &lt;/span&gt;&lt;code style="font-family: 'Courier New', Courier, mono; font-size: 11pt; "&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt;SpinLock&lt;/span&gt;&lt;/code&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt;’s secret is that instead of using a system call, the way ‘&lt;/span&gt;&lt;code lang="cs"   style="font-family:'Courier New', Courier, mono;font-size:11pt;"&gt;&lt;span class="code-keyword"&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt;lock&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt;’ does, it uses ‘&lt;/span&gt;&lt;code style="font-family: 'Courier New', Courier, mono; font-size: 11pt; "&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt;SpinWait()&lt;/span&gt;&lt;/code&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt;’ to let the other core release the lock. Of course, if the computer hasn’t got another core, this is useless. So, in order to know whether I could use ‘&lt;/span&gt;&lt;code style="font-family: 'Courier New', Courier, mono; font-size: 11pt; "&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt;SpinLock&lt;/span&gt;&lt;/code&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt;’ effectively, I first needed to validate that the machine I was running had more than one processor. Hence the code above…&lt;/span&gt;&lt;/p&gt;&lt;h2 style="font-family: Verdana, Helvetica, Arial, sans-serif; font-size: 13pt; font-weight: bold; "&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt;Examples and notes&lt;/span&gt;&lt;/h2&gt;&lt;ol&gt;&lt;li style="font-family: Verdana, Helvetica, Arial, sans-serif; font-size: 10pt; "&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt;There are several ‘SpinLock’ implementations, I found this one to be particularly nice: &lt;/span&gt;&lt;a href="http://www.bluebytesoftware.com/blog/PermaLink,guid,fd6ed0d7-2849-4ca1-9619-74cd5713c3c0.aspx" target="_blank" style="text-decoration: none; "&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt;http://www.bluebytesoftware.com/blog/PermaLink,guid,fd6ed0d7-2849-4ca1-9619-74cd5713c3c0.aspx&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;&lt;li style="font-family: Verdana, Helvetica, Arial, sans-serif; font-size: 10pt; "&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt;Test my processor detector live for yourself at &lt;/span&gt;&lt;a href="http://yogil.com/yogi/processors.html" target="_blank" style="text-decoration: none; "&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt;http://yogil.com/yogi/processors.html&lt;/span&gt;&lt;/a&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt;. You can see how many processors your computer is running manually by clicking ‘Properties’ on ‘My Computer’ (Windows machines).&lt;/span&gt;&lt;/li&gt;&lt;/ol&gt;&lt;h2 style="font-family: Verdana, Helvetica, Arial, sans-serif; font-size: 13pt; font-weight: bold; "&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt;Ideas for the future&lt;/span&gt;&lt;/h2&gt;&lt;ul&gt;&lt;li style="font-family: Verdana, Helvetica, Arial, sans-serif; font-size: 10pt; "&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt;Because of the risk of false positives, it would probably be advisable to run the method several times and use the most frequent outcome. This will certainly improve results.&lt;/span&gt;&lt;/li&gt;&lt;li style="font-family: Verdana, Helvetica, Arial, sans-serif; font-size: 10pt; "&gt;&lt;span class="Apple-style-span"  style="color:#FFFFFF;"&gt;By using multiple threads, it should be possible to discover the exact amount of processors, and not merely whether the machine has one or more.&lt;/span&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6515147997242787617-7773624412148562638?l=eylonyogev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://eylonyogev.blogspot.com/feeds/7773624412148562638/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6515147997242787617&amp;postID=7773624412148562638' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6515147997242787617/posts/default/7773624412148562638'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6515147997242787617/posts/default/7773624412148562638'/><link rel='alternate' type='text/html' href='http://eylonyogev.blogspot.com/2009/02/how-to-determine-processor-count-from.html' title=''/><author><name>Eylon Yogev</name><uri>http://www.blogger.com/profile/09748464292766314155</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://3.bp.blogspot.com/_sMu4s8uus94/SMmNcXyaijI/AAAAAAAAA5Y/R48AFTXYQp8/S220/n509798273_4395.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6515147997242787617.post-4484705171365375950</id><published>2008-12-14T10:06:00.000-08:00</published><updated>2008-12-14T10:08:35.882-08:00</updated><title type='text'>A new Ubiquity mashup with headup</title><content type='html'>I've written a really cool post about this. Check it out here:&lt;a href="http://blog.headup.com/2008/12/headup-ubiquity-mashup/"&gt; http://blog.headup.com/2008/12/headup-ubiquity-mashup/&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6515147997242787617-4484705171365375950?l=eylonyogev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://eylonyogev.blogspot.com/feeds/4484705171365375950/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6515147997242787617&amp;postID=4484705171365375950' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6515147997242787617/posts/default/4484705171365375950'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6515147997242787617/posts/default/4484705171365375950'/><link rel='alternate' type='text/html' href='http://eylonyogev.blogspot.com/2008/12/new-ubiquity-mashup-with-headup.html' title='A new Ubiquity mashup with headup'/><author><name>Eylon Yogev</name><uri>http://www.blogger.com/profile/09748464292766314155</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://3.bp.blogspot.com/_sMu4s8uus94/SMmNcXyaijI/AAAAAAAAA5Y/R48AFTXYQp8/S220/n509798273_4395.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6515147997242787617.post-8778620095026826587</id><published>2008-09-24T04:48:00.001-07:00</published><updated>2008-09-24T04:51:20.805-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Computers'/><category scheme='http://www.blogger.com/atom/ns#' term='Javascript'/><category scheme='http://www.blogger.com/atom/ns#' term='programming'/><category scheme='http://www.blogger.com/atom/ns#' term='c#'/><category scheme='http://www.blogger.com/atom/ns#' term='jit'/><title type='text'>Going away</title><content type='html'>I'll not be writing in the next month because I'll be traveling in India.&lt;br /&gt;But I'll leave you with this poem I wrote:&lt;br /&gt;&lt;br /&gt;(On the melody on Spider Pig)&lt;br /&gt;Javascript, Javascript,&lt;br /&gt;Does whatever a Javascript does.&lt;br /&gt;Can it run very fast?&lt;br /&gt;No it can't, it's a script.&lt;br /&gt;&lt;br /&gt;Javascript, Javascript,&lt;br /&gt;Does whatever a Javascript does.&lt;br /&gt;Will it run ever fast?&lt;br /&gt;Yes it will, it will JIT.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6515147997242787617-8778620095026826587?l=eylonyogev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://eylonyogev.blogspot.com/feeds/8778620095026826587/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6515147997242787617&amp;postID=8778620095026826587' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6515147997242787617/posts/default/8778620095026826587'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6515147997242787617/posts/default/8778620095026826587'/><link rel='alternate' type='text/html' href='http://eylonyogev.blogspot.com/2008/09/going-away.html' title='Going away'/><author><name>Eylon Yogev</name><uri>http://www.blogger.com/profile/09748464292766314155</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://3.bp.blogspot.com/_sMu4s8uus94/SMmNcXyaijI/AAAAAAAAA5Y/R48AFTXYQp8/S220/n509798273_4395.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6515147997242787617.post-4641551278289125847</id><published>2008-09-11T14:18:00.000-07:00</published><updated>2008-09-11T14:26:26.243-07:00</updated><title type='text'>Congratulation!</title><content type='html'>It's about time I open a blog. Things that I'll tell about here: Silverlight, Firefox, c# and everything in between.&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Enjoy.&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6515147997242787617-4641551278289125847?l=eylonyogev.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://eylonyogev.blogspot.com/feeds/4641551278289125847/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6515147997242787617&amp;postID=4641551278289125847' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6515147997242787617/posts/default/4641551278289125847'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6515147997242787617/posts/default/4641551278289125847'/><link rel='alternate' type='text/html' href='http://eylonyogev.blogspot.com/2008/09/congratulation.html' title='Congratulation!'/><author><name>Eylon Yogev</name><uri>http://www.blogger.com/profile/09748464292766314155</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='24' height='32' src='http://3.bp.blogspot.com/_sMu4s8uus94/SMmNcXyaijI/AAAAAAAAA5Y/R48AFTXYQp8/S220/n509798273_4395.jpg'/></author><thr:total>0</thr:total></entry></feed>
