I have searched the User community and google and have not been able to get a definitive answer to my question.
I have found by experimentation that one timer will not interrupt another. They are uninterruptable. For example, I ran two timers, A and B, A was set at 1 sec and executed a simple fprintf stm, B conversely was set to 5 seconds and took several seconds to execute. Once B kicked in, A had to wait till B got finished. And then they operated A A B A A B ... as expected since the default is to drop serviced requests, (think the double A is because two of them get in the stack before the A timer starts dropping).
My question is can I make it so A will interrupt B, i.e., set the priority of A higher than B.
My application requires a precisely timed execution of one Fcn, (A's Fcn), while B can execute at any time in the background.
"Jerry Gregoire" <jerryglenREMOVETHIS@neuralynx.com> wrote in message <email@example.com>...
> I have searched the User community and google and have not been able to get a definitive answer to my question.
> I have found by experimentation that one timer will not interrupt another. They are uninterruptable. For example, I ran two timers, A and B, A was set at 1 sec and executed a simple fprintf stm, B conversely was set to 5 seconds and took several seconds to execute. Once B kicked in, A had to wait till B got finished. And then they operated A A B A A B ... as expected since the default is to drop serviced requests, (think the double A is because two of them get in the stack before the A timer starts dropping).
> My question is can I make it so A will interrupt B, i.e., set the priority of A higher than B.
> My application requires a precisely timed execution of one Fcn, (A's Fcn), while B can execute at any time in the background.
I did not get satisfactory ans so I submitted the issue to Matlab technical support. The upshot is that a timer will not interrupt another timer, although it is something that may be fixed someday in the future. This seems to be a glaring deficiency on Matlab's part.
This should be possible even with single threading, (Matlab is not multithreading capable), but ML can't do it. This is disappointing because it limits any 'quasi real time Matlab' useless if more than one timer is running. I am currently using 2011B, however I don't think it has changed. Here is the conversation I had with the Mathworks if anyone is interested.
I am writing in reference to your Service Request # 1-K3BW22 regarding 'Timer priority'.
I had some more questions regarding the issue. These are as follows:-
1) Do you want the Timer B to start after Timer A finishes executing?
2) Do you want Timer A and Timer B to run concurrently once Timer B starts after 5 seconds?
Thanks for the reply. The idea is simply to allow a timer to exercise
real time control, i.e., its function will execute after the current
statement, (any statement), is finished. Ideally, it would be great if
it could execute immediately, but this would require multi-threading,
which as I understand Matlab does not currently support.
So if BFcn is executing, AFcn would interrupt at the conclusion of the
current statement in BFcn, run and return control to BFcn when AFcn is
finished. It would operate just the same as if a non timer function or
script were executing. From what I have been able to determine a timer
function, (A), will interrupt another function unless the other
function is a timer function, (B). In this case the second timer
function, (B), must complete before control is handed over the first
timer function, (A).
2) Do you want Timer A and Timer B to run concurrently once Timer B
starts after 5 seconds?
In the code I sent you, Timer A and B start at the same time, B simply
waits 5 seconds until its function executes.
Thank You for your answers. One possible suggestion that I can offer is that instead of starting both the timers in the main function, you can define a 'StopFcn' for Timer A(which is the callback executed once Timer A stops executing), in which you can start Timer B. Therefore, Timer B will start as soon as Timer A stops.
Details about StopFcn have been shared in the following documentation page for Timer Objects.
Let me know if a 'StopFcn' will help you achieve your use case.
The problem is still the same. If BFcn is executing, A cannot
interrupt it. This would only work if the time to execute timer BFcn <
timer A period which is not guaranteed. In the example code I sent,
the time of execution for BFcn is 8.34 seconds, (on my machine),
while the period of timer A is 1 second.
I am writing in reference to your Service Request # 1-K3BW22 regarding 'Timer priority'.
Unfortunately, two timers won't interrupt one another. The functionality used to control GUI callbacks (UIWAIT, UIRESUME, WAITFOR, etc). does not behave as documented when used in TIMER callbacks. Only callbacks corresponding to the same timer may be interrupted using the 'BusyMode' property.
An enhancement has alrady been submitted in order to incorporate such an attribute in a future release. I will, however, not be able to suggest a workaround at the moment. In case you can share the application that you are working on, which requires this attribute, maybe I will be able to suggest a different workaround to approach that problem.
I wouldn't hope such limitation would satisfactory getting solved any soon. In order to make a real concurrent runs among timers, All MATLAB builtin functions has to be thread safe. This is really a major change from TMW.
You should forget about MATLAB if you want to get the realtime job done, or limit the goal to very specific tasks (acquisition, calculation) with MEX programing.
You can think of your watch list as threads that you have bookmarked.
You can add tags, authors, threads, and even search results to your watch list. This way you can easily keep track of topics that you're interested in. To view your watch list, click on the "My Newsreader" link.
To add items to your watch list, click the "add to watch list" link at the bottom of any page.
To add search criteria to your watch list, search for the desired term in the search box. Click on the "Add this search to my watch list" link on the search results page.
You can also add a tag to your watch list by searching for the tag with the directive "tag:tag_name" where tag_name is the name of the tag you would like to watch.
To add an author to your watch list, go to the author's profile page and click on the "Add this author to my watch list" link at the top of the page. You can also add an author to your watch list by going to a thread that the author has posted to and clicking on the "Add this author to my watch list" link. You will be notified whenever the author makes a post.
To add a thread to your watch list, go to the thread page and click the "Add this thread to my watch list" link at the top of the page.
The newsgroups are a worldwide forum that is open to everyone. Newsgroups are used to discuss a huge range of topics, make announcements, and trade files.
Discussions are threaded, or grouped in a way that allows you to read a posted message and all of its replies in chronological order. This makes it easy to follow the thread of the conversation, and to see what’s already been said before you post your own reply or make a new posting.
Newsgroup content is distributed by servers hosted by various organizations on the Internet. Messages are exchanged and managed using open-standard protocols. No single entity “owns” the newsgroups.
There are thousands of newsgroups, each addressing a single topic or area of interest. The MATLAB Central Newsreader posts and displays messages in the comp.soft-sys.matlab newsgroup.
You can use the integrated newsreader at the MATLAB Central website to read and post messages in this newsgroup. MATLAB Central is hosted by MathWorks.
Messages posted through the MATLAB Central Newsreader are seen by everyone using the newsgroups, regardless of how they access the newsgroups. There are several advantages to using MATLAB Central.
Your MATLAB Central account is tied to your MathWorks Account for easy access.
Use the Email Address of Your Choice
The MATLAB Central Newsreader allows you to define an alternative email address as your posting address, avoiding clutter in your primary mailbox and reducing spam.
Most newsgroup spam is filtered out by the MATLAB Central Newsreader.
Messages can be tagged with a relevant label by any signed-in user. Tags can be used as keywords to find particular files of interest, or as a way to categorize your bookmarked postings. You may choose to allow others to view your tags, and you can view or search others’ tags as well as those of the community at large. Tagging provides a way to see both the big trends and the smaller, more obscure ideas and applications.
Setting up watch lists allows you to be notified of updates made to postings selected by author, thread, or any search variable. Your watch list notifications can be sent by email (daily digest or immediate), displayed in My Newsreader, or sent via RSS feed.