<?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: Controlling callback re-entrancy	</title>
	<atom:link href="https://undocumentedmatlab.com/articles/controlling-callback-re-entrancy/feed" rel="self" type="application/rss+xml" />
	<link>https://undocumentedmatlab.com/articles/controlling-callback-re-entrancy?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=controlling-callback-re-entrancy</link>
	<description>Professional Matlab consulting, development and training</description>
	<lastBuildDate>Wed, 29 Jul 2020 17:13:54 +0000</lastBuildDate>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.7.3</generator>
	<item>
		<title>
		By: Jan		</title>
		<link>https://undocumentedmatlab.com/articles/controlling-callback-re-entrancy#comment-508786</link>

		<dc:creator><![CDATA[Jan]]></dc:creator>
		<pubDate>Wed, 29 Jul 2020 17:13:54 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=2403#comment-508786</guid>

					<description><![CDATA[Is there a reason why this function was removed from the Matlab File Exchange?

I prefer a simplified DBSTACK solution:
&lt;pre lang=&quot;matlab&quot;&gt;
function flag = isMultipleCall()
   s = dbstack();
   flag = (numel(s) &gt; 2) &amp;&amp; (sum(strcmp(s(2).name, {s.name})) &gt; 1);
end
&lt;/pre&gt;]]></description>
			<content:encoded><![CDATA[<p>Is there a reason why this function was removed from the Matlab File Exchange?</p>
<p>I prefer a simplified DBSTACK solution:</p>
<pre lang="matlab">
function flag = isMultipleCall()
   s = dbstack();
   flag = (numel(s) > 2) &#038;& (sum(strcmp(s(2).name, {s.name})) > 1);
end
</pre>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Christos Oreinos		</title>
		<link>https://undocumentedmatlab.com/articles/controlling-callback-re-entrancy#comment-402299</link>

		<dc:creator><![CDATA[Christos Oreinos]]></dc:creator>
		<pubDate>Tue, 07 Mar 2017 16:32:03 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=2403#comment-402299</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://undocumentedmatlab.com/articles/controlling-callback-re-entrancy#comment-53843&quot;&gt;Malcolm Lidierth&lt;/a&gt;.

I also used a solution almost similar to Arda&#039;s (using a persistent variable). After reading this post I opted for the isMultipleCall() because, like Malcolm very very wisely says, I had problems when internal callback errors (which were not fatal in my case) or Ctrl+C stopped the callback that I was controlling for recursive call. In this case the callback could not be run again unless I explicitly cleared all variables.]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://undocumentedmatlab.com/articles/controlling-callback-re-entrancy#comment-53843">Malcolm Lidierth</a>.</p>
<p>I also used a solution almost similar to Arda&#8217;s (using a persistent variable). After reading this post I opted for the isMultipleCall() because, like Malcolm very very wisely says, I had problems when internal callback errors (which were not fatal in my case) or Ctrl+C stopped the callback that I was controlling for recursive call. In this case the callback could not be run again unless I explicitly cleared all variables.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Elliott		</title>
		<link>https://undocumentedmatlab.com/articles/controlling-callback-re-entrancy#comment-315085</link>

		<dc:creator><![CDATA[Elliott]]></dc:creator>
		<pubDate>Thu, 20 Feb 2014 21:18:26 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=2403#comment-315085</guid>

					<description><![CDATA[This has been a really useful post and has really helped out a Matlab GUI that I have.

I&#039;m confused on one count though, and I&#039;m sure this is just my lack of understanding of how Matlab runs behind the scenes.  Why does this not work with a figure&#039;s ResizeFcn callback?  I would really like to have a custom resize, but it needs to be safe against re-entrancy.  Currently, I&#039;d handle this with a timer, but I&#039;d rather not have to use that.

Is there a way to get this to work with the ResizeFcn?

Thanks.]]></description>
			<content:encoded><![CDATA[<p>This has been a really useful post and has really helped out a Matlab GUI that I have.</p>
<p>I&#8217;m confused on one count though, and I&#8217;m sure this is just my lack of understanding of how Matlab runs behind the scenes.  Why does this not work with a figure&#8217;s ResizeFcn callback?  I would really like to have a custom resize, but it needs to be safe against re-entrancy.  Currently, I&#8217;d handle this with a timer, but I&#8217;d rather not have to use that.</p>
<p>Is there a way to get this to work with the ResizeFcn?</p>
<p>Thanks.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Rafael		</title>
		<link>https://undocumentedmatlab.com/articles/controlling-callback-re-entrancy#comment-208621</link>

		<dc:creator><![CDATA[Rafael]]></dc:creator>
		<pubDate>Mon, 03 Jun 2013 20:56:54 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=2403#comment-208621</guid>

					<description><![CDATA[Thanks a lot for the answer @Yair!
I&#039;m not sure your solution of using a timer to re-execute the function will work for me. I have thought of that solution for a while, but let&#039;s say you have two things that must happen in a particular order, and only the first one is the one that must be re-executed by the timer. How do I hold the execution of the second process until the first one has for sure executed? I get back to the polling loop problem! Would I have to convert all of my processes into timers that are constantly firing to check if it&#039;s OK to execute in the right order? My whole system would be come a nightmare if I have to do that!]]></description>
			<content:encoded><![CDATA[<p>Thanks a lot for the answer @Yair!<br />
I&#8217;m not sure your solution of using a timer to re-execute the function will work for me. I have thought of that solution for a while, but let&#8217;s say you have two things that must happen in a particular order, and only the first one is the one that must be re-executed by the timer. How do I hold the execution of the second process until the first one has for sure executed? I get back to the polling loop problem! Would I have to convert all of my processes into timers that are constantly firing to check if it&#8217;s OK to execute in the right order? My whole system would be come a nightmare if I have to do that!</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Yair Altman		</title>
		<link>https://undocumentedmatlab.com/articles/controlling-callback-re-entrancy#comment-208113</link>

		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Sat, 01 Jun 2013 17:41:16 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=2403#comment-208113</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://undocumentedmatlab.com/articles/controlling-callback-re-entrancy#comment-207900&quot;&gt;Rafael&lt;/a&gt;.

@Rafael - if the callback&#039;ed object supports the &lt;b&gt;BusyAction&lt;/b&gt; and &lt;b&gt;Interruptable&lt;/b&gt; properties, then setting these would be the easiest choice. Otherwise, you could preserve the callback parameters in some persistent data struct (e.g., a cell array) and set a timer object to run the callback function programmatically in a second or two.]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://undocumentedmatlab.com/articles/controlling-callback-re-entrancy#comment-207900">Rafael</a>.</p>
<p>@Rafael &#8211; if the callback&#8217;ed object supports the <b>BusyAction</b> and <b>Interruptable</b> properties, then setting these would be the easiest choice. Otherwise, you could preserve the callback parameters in some persistent data struct (e.g., a cell array) and set a timer object to run the callback function programmatically in a second or two.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Rafael		</title>
		<link>https://undocumentedmatlab.com/articles/controlling-callback-re-entrancy#comment-207900</link>

		<dc:creator><![CDATA[Rafael]]></dc:creator>
		<pubDate>Fri, 31 May 2013 22:58:50 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=2403#comment-207900</guid>

					<description><![CDATA[This is very interesting. But how would you handle the case when you don&#039;t want to bail out of the callback if it&#039;s already executing, but you want to wait instead for the first instance to finish? The obvious solution of putting a polling loop does not work because the loop will keep Matlab from finishing the execution of the first instance. I can&#039;t seem to find a solution to that problem!
Thanks!]]></description>
			<content:encoded><![CDATA[<p>This is very interesting. But how would you handle the case when you don&#8217;t want to bail out of the callback if it&#8217;s already executing, but you want to wait instead for the first instance to finish? The obvious solution of putting a polling loop does not work because the loop will keep Matlab from finishing the execution of the first instance. I can&#8217;t seem to find a solution to that problem!<br />
Thanks!</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Michele		</title>
		<link>https://undocumentedmatlab.com/articles/controlling-callback-re-entrancy#comment-73084</link>

		<dc:creator><![CDATA[Michele]]></dc:creator>
		<pubDate>Thu, 02 Feb 2012 08:49:34 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=2403#comment-73084</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://undocumentedmatlab.com/articles/controlling-callback-re-entrancy#comment-73083&quot;&gt;Yair Altman&lt;/a&gt;.

@Yair - Thank you very much for the quick reply, I&#039;ll definitely give it a try.]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://undocumentedmatlab.com/articles/controlling-callback-re-entrancy#comment-73083">Yair Altman</a>.</p>
<p>@Yair &#8211; Thank you very much for the quick reply, I&#8217;ll definitely give it a try.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Michele		</title>
		<link>https://undocumentedmatlab.com/articles/controlling-callback-re-entrancy#comment-73082</link>

		<dc:creator><![CDATA[Michele]]></dc:creator>
		<pubDate>Thu, 02 Feb 2012 08:31:22 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=2403#comment-73082</guid>

					<description><![CDATA[This utility is very interesting, but due to the use of &#039;dbstack&#039; it wouldn&#039;t work in compiled applications.
Do you know of any easy workaround for that?
Thank you very much]]></description>
			<content:encoded><![CDATA[<p>This utility is very interesting, but due to the use of &#8216;dbstack&#8217; it wouldn&#8217;t work in compiled applications.<br />
Do you know of any easy workaround for that?<br />
Thank you very much</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Yair Altman		</title>
		<link>https://undocumentedmatlab.com/articles/controlling-callback-re-entrancy#comment-73083</link>

		<dc:creator><![CDATA[Yair Altman]]></dc:creator>
		<pubDate>Wed, 01 Feb 2012 23:42:16 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=2403#comment-73083</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://undocumentedmatlab.com/articles/controlling-callback-re-entrancy#comment-73082&quot;&gt;Michele&lt;/a&gt;.

@Michele - you could store a temporary flag in a persistent variable or the handle&#039;s &lt;b&gt;ApplicationData/UserData&lt;/b&gt;, or a variant of these. For example:

&lt;pre lang=&quot;matlab&quot;&gt;
% Variant1
function myCallbackFcn1(hObject,eventData,varargin)
   persistent inCallback
   if ~isempty(inCallback),  return;  end
   inCallback = true;
   try
       % do something useful here
   catch
       % error trapping here
   end
   pause(0.001); drawnow;  % give all other events a chance to bail out above
   inCallback = [];
end  % myCallbackFcn1

% Variant2
function myCallbackFcn2(hObject,eventData,varargin)
   inCallback = getappdata(hObject,&#039;inCallback&#039;);
   if ~isempty(inCallback),  return;  end
   setappdata(hObject,&#039;inCallback&#039;,true);
   try
       % do something useful here
   catch
       % error trapping here
   end
   pause(0.001); drawnow;  % give all other events a chance to bail out above
   setappdata(hObject,&#039;inCallback&#039;,[]);
end  % myCallbackFcn2
&lt;/pre&gt;]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://undocumentedmatlab.com/articles/controlling-callback-re-entrancy#comment-73082">Michele</a>.</p>
<p>@Michele &#8211; you could store a temporary flag in a persistent variable or the handle&#8217;s <b>ApplicationData/UserData</b>, or a variant of these. For example:</p>
<pre lang="matlab">
% Variant1
function myCallbackFcn1(hObject,eventData,varargin)
   persistent inCallback
   if ~isempty(inCallback),  return;  end
   inCallback = true;
   try
       % do something useful here
   catch
       % error trapping here
   end
   pause(0.001); drawnow;  % give all other events a chance to bail out above
   inCallback = [];
end  % myCallbackFcn1

% Variant2
function myCallbackFcn2(hObject,eventData,varargin)
   inCallback = getappdata(hObject,'inCallback');
   if ~isempty(inCallback),  return;  end
   setappdata(hObject,'inCallback',true);
   try
       % do something useful here
   catch
       % error trapping here
   end
   pause(0.001); drawnow;  % give all other events a chance to bail out above
   setappdata(hObject,'inCallback',[]);
end  % myCallbackFcn2
</pre>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Arda		</title>
		<link>https://undocumentedmatlab.com/articles/controlling-callback-re-entrancy#comment-54522</link>

		<dc:creator><![CDATA[Arda]]></dc:creator>
		<pubDate>Sat, 20 Aug 2011 19:40:32 +0000</pubDate>
		<guid isPermaLink="false">http://undocumentedmatlab.com/?p=2403#comment-54522</guid>

					<description><![CDATA[By the way, if the handle has properties &#039;BusyAction&#039; and &#039;Interruptable&#039; (like figure windows, uicontrols, etc.), setting &#039;cancel&#039; and &#039;off&#039; is always a choice. That should do the same...]]></description>
			<content:encoded><![CDATA[<p>By the way, if the handle has properties &#8216;BusyAction&#8217; and &#8216;Interruptable&#8217; (like figure windows, uicontrols, etc.), setting &#8216;cancel&#8217; and &#8216;off&#8217; is always a choice. That should do the same&#8230;</p>
]]></content:encoded>
		
			</item>
	</channel>
</rss>
