<?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:blogger='http://schemas.google.com/blogger/2008' 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-3312848737347758930</id><updated>2024-08-28T10:28:45.851-07:00</updated><category term="codes"/><category term="computer science"/><category term="programming"/><category term="python"/><category term="GUI"/><category term="lock"/><category term="program freeze"/><category term="race condition"/><category term="vb"/><title type='text'>Burn your Head</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://codejam.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3312848737347758930/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://codejam.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Shadman Anwer</name><uri>http://www.blogger.com/profile/18272246171565808968</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>3</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-3312848737347758930.post-8970578192374665129</id><published>2014-09-18T01:03:00.001-07:00</published><updated>2014-11-20T00:41:24.774-08:00</updated><title type='text'></title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;br /&gt;
Flipkart Ad
&lt;iframe src=&quot;http://www.flipkart.com/affiliate/displayWidget?affrid=WRID-141102789910471268&quot; style=&quot;width:120px;height:240px;&quot; scrolling=&quot;no&quot; marginwidth=&quot;0&quot; marginheight=&quot;0&quot; frameborder=&quot;0&quot; &gt;&lt;/iframe&gt;

&lt;iframe src=&quot;http://www.flipkart.com/affiliate/displayWidget?affrid=WRID-141102793122915043&quot; style=&quot;width:120px;height:240px;&quot; scrolling=&quot;no&quot; marginwidth=&quot;0&quot; marginheight=&quot;0&quot; frameborder=&quot;0&quot; &gt;&lt;/iframe&gt;

&lt;a href=&quot;http://www.flipkart.com/moto-x-16-gb/p/itmdwgffrgc885qt?pid=MOBDSGU27YGJAZNB&amp;affid=shadmanph&quot;&gt;&lt;img src=&quot;http://img5a.flixcart.com/www/prod/images/buy_btn_3-0b867813.png&quot;&gt;&lt;/a&gt;


&lt;iframe src=&quot;http://www.flipkart.com/affiliate/displayWidget?affrid=WRID-141647076872954162&quot; style=&quot;width:120px;height:240px;&quot; scrolling=&quot;no&quot; marginwidth=&quot;0&quot; marginheight=&quot;0&quot; frameborder=&quot;0&quot; &gt;&lt;/iframe&gt;

&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://codejam.blogspot.com/feeds/8970578192374665129/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://codejam.blogspot.com/2014/09/blog-post.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3312848737347758930/posts/default/8970578192374665129'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3312848737347758930/posts/default/8970578192374665129'/><link rel='alternate' type='text/html' href='http://codejam.blogspot.com/2014/09/blog-post.html' title=''/><author><name>Shadman Anwer</name><uri>http://www.blogger.com/profile/18272246171565808968</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3312848737347758930.post-480041388676025949</id><published>2012-08-25T11:59:00.000-07:00</published><updated>2012-08-25T12:00:31.393-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="codes"/><category scheme="http://www.blogger.com/atom/ns#" term="computer science"/><category scheme="http://www.blogger.com/atom/ns#" term="GUI"/><category scheme="http://www.blogger.com/atom/ns#" term="lock"/><category scheme="http://www.blogger.com/atom/ns#" term="program freeze"/><category scheme="http://www.blogger.com/atom/ns#" term="programming"/><category scheme="http://www.blogger.com/atom/ns#" term="python"/><category scheme="http://www.blogger.com/atom/ns#" term="race condition"/><title type='text'>GUI Lock Down</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;span style=&quot;font-size: x-small;&quot;&gt;Dear folks, sorry for the delay in my this post (that is if any of you were waiting to read). &lt;/span&gt;&lt;br /&gt;
In this post I would mainly be stating a few points that should be in mind when you are are making a &lt;b&gt;GUI program&lt;/b&gt;. This may be helpful to you and save a lot of head aches trying to debug the problem as it occurred to me.&lt;br /&gt;
&lt;br /&gt;
As you all may know that when you click a button on a window, the window is in a &lt;b&gt;frozen state&lt;/b&gt; until the execution of codes in the handler is completed. You would usually make the event handler of the button do some calculations and then reflect a few changes in the interface. Your program is a single thread, every thing happens on the UI thread, and you are out of trouble.&lt;br /&gt;
&lt;br /&gt;
But what if your program is little more complex and other &lt;b&gt;threads&lt;/b&gt; try to edit the UI components. What if there is &lt;b&gt;shared memory&lt;/b&gt; and both the user interface thread and other threads acquire lock to these locations.&lt;br /&gt;
&lt;br /&gt;
Here&#39;s the method of action GUI frameworks usually follow:&lt;br /&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;When ever a thread tries to access UI components, it acquires a &lt;b&gt;lock&lt;/b&gt; on the user interface.&lt;/li&gt;
&lt;li&gt;Any other call to the user interface will have to wait for the previously acquired lock to be released.&lt;/li&gt;
&lt;li&gt;The button click event also acquires lock on the UI and releases it when its handlers execution is over.&lt;/li&gt;
&lt;/ul&gt;
Now here&#39;s the question, when does the program go into a &lt;b&gt;Lock Down State&lt;/b&gt; (the program hangs execution due to some reasons) (I just call the state a lock down state).&lt;br /&gt;
&lt;br /&gt;
Let me give you an example of such a situation. You will get the idea from it.&lt;br /&gt;
The program design is as follows: &lt;br /&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;Your program has two threads: &lt;br /&gt;&lt;ol&gt;
&lt;li&gt;The &lt;b&gt;User Interface&lt;/b&gt; thread. This holds all the UI objects.&lt;/li&gt;
&lt;li&gt;Another thread, say &lt;b&gt;Thread B&lt;/b&gt;, which samples data from a given steam at a particular rate (e.g. an Internet stream or a device connected to a serial port). &lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;li&gt;&amp;nbsp;You have a &lt;b&gt;function fun1()&lt;/b&gt; that is called by thread B and also by the button click event handler of the UI thread. This function has codes that &lt;b&gt;acquires lock&lt;/b&gt; on object say &lt;b&gt;LO1&lt;/b&gt;&lt;/li&gt;
&lt;li&gt;&lt;b&gt;Thread B&lt;/b&gt; and a&lt;b&gt; button click &lt;/b&gt;on the UI, both try to change the text in a &lt;b&gt;text box &lt;/b&gt;on the UI.&lt;/li&gt;
&lt;/ul&gt;
&amp;nbsp;The program will go into Lock Down State when the following occurs:&lt;br /&gt;
&lt;ul style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;&lt;b&gt;Thread B&lt;/b&gt; has acquire lock on lock object &lt;b&gt;LB1&lt;/b&gt;.&lt;/li&gt;
&lt;li&gt;User has clicked the &lt;b&gt;button&lt;/b&gt; and click event has acquired &lt;b&gt;lock on the UI&lt;/b&gt;.&lt;/li&gt;
&lt;li&gt;&lt;b&gt;Thread B&lt;/b&gt; is waiting for the &lt;b&gt;UI lock&lt;/b&gt; to be released so that it can edit the text in the text box.&lt;/li&gt;
&lt;li&gt;The &lt;b&gt;UI lock&lt;/b&gt; is not being released by the &lt;b&gt;click event&lt;/b&gt; as it is waiting for &lt;b&gt;Thread B&lt;/b&gt; to release the lock it has acquired.&amp;nbsp;&lt;/li&gt;
&lt;/ul&gt;
And thus the Lock Down State is reached. It is really frustrating to be stuck in this situation and not know about it.&lt;br /&gt;
&lt;br /&gt;
There are two ways I would suggest in which you can avoid this situation:&lt;br /&gt;
&lt;ol style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;Never try to access UI components when there is a Lock acquired. Always free every lock object before doing so.&lt;/li&gt;
&lt;li&gt;Put the execution part of the button event handler into another thread and free the UI (Clicking the button in this case will simply just start the thread execution).&lt;/li&gt;
&lt;/ol&gt;
These two ways will surely help you out. I personally prefer creating new threads and making them execute.Your UI will never &lt;b&gt;freeze&lt;/b&gt; in this situation also.&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://codejam.blogspot.com/feeds/480041388676025949/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://codejam.blogspot.com/2012/08/gui-lock-down.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3312848737347758930/posts/default/480041388676025949'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3312848737347758930/posts/default/480041388676025949'/><link rel='alternate' type='text/html' href='http://codejam.blogspot.com/2012/08/gui-lock-down.html' title='GUI Lock Down'/><author><name>Shadman Anwer</name><uri>http://www.blogger.com/profile/18272246171565808968</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3312848737347758930.post-6907268941786136816</id><published>2012-06-27T22:58:00.000-07:00</published><updated>2012-06-29T02:42:54.777-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="codes"/><category scheme="http://www.blogger.com/atom/ns#" term="computer science"/><category scheme="http://www.blogger.com/atom/ns#" term="programming"/><category scheme="http://www.blogger.com/atom/ns#" term="python"/><category scheme="http://www.blogger.com/atom/ns#" term="vb"/><title type='text'>Whose head to burn?</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
When I am in the hostel, there is always some one to share my 
frustration with, if I have any while doing some computer science 
assignment (I am only a minor in it). Well presently, all of 
it is with me.&lt;br /&gt;
On the brighter side, I&#39;ve learnt a lot (Though I 
had to eat my head off). So I thought of sharing my wisdom out here. People might find this stuff pretty useful.&lt;br /&gt;
&lt;br /&gt;
Here are the guidelines for reading the later posts.&lt;br /&gt;
&lt;ol style=&quot;text-align: left;&quot;&gt;
&lt;li&gt;This blog is dedicated to share experiences in programming.&lt;/li&gt;
&lt;li&gt;This is not a leisure time spending blog. (Except if you are a nut case and do stuff like these in your leisure time.)&lt;/li&gt;
&lt;li&gt;If you ever try to say that I have made spelling mistakes and I&#39;m writing dumb things, I WILL KILL YOU. Believe me.&lt;/li&gt;
&lt;/ol&gt;
I am working pretty extensively in Python these days so maybe 
I&#39;ll talk about it first (Not right now obviously, in my later posts). 
Till then, Burn your head.!&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://codejam.blogspot.com/feeds/6907268941786136816/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://codejam.blogspot.com/2012/06/whose-head-to-burn.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3312848737347758930/posts/default/6907268941786136816'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3312848737347758930/posts/default/6907268941786136816'/><link rel='alternate' type='text/html' href='http://codejam.blogspot.com/2012/06/whose-head-to-burn.html' title='Whose head to burn?'/><author><name>Shadman Anwer</name><uri>http://www.blogger.com/profile/18272246171565808968</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>