Running two independant background tasks on two cores

2 visualizaciones (últimos 30 días)
mitraz dobraz
mitraz dobraz el 30 de Mzo. de 2023
Respondida: Deep el 12 de Sept. de 2024
I coded a program that opens a GUI and runs a script in the background using a timer. Very basically, the background script checks (as often as possible) for changes from a Tucker Davis Technologies (TDT) interface and runs indefinitely until it is stopped from the GUI. The GUI is used to edit variables on the fly, and to display some input from the TDT interface.
I now need to get data from an eyetracker (on the fly) at the same time. The easiest way would have been to run a second timer in parallel with the first one. But of course, both timers run on the same core and prevent eachother to run properly.
Is there a solution to achieve what I need to do?
I have the parallel computing toolbox installed.
Thanks.

Respuestas (1)

Deep
Deep el 12 de Sept. de 2024
Hi Mitraz,
To run two independent background tasks on separate cores in MATLAB, you can utilize the Parallel Computing Toolbox to execute timer objects in separate tasks. This approach allows each timer to be processed by a different MATLAB worker, effectively overcoming the limitation of both timers running on the same core.
I suggest referring to this MATLAB staff answer which provides two example scripts, “paralleltimertest_new.m” and “timerfun_new.m”, that achieve your desired functionality - https://www.mathworks.com/matlabcentral/answers/98271-how-can-i-create-timer-objects-which-are-running-in-parallel-in-matlab-7-13-r2011b.
Although the original answer was for R2011b, I verified that these scripts work correctly in R2019b.
You may also find the following related MATLAB Answers to be helpful:
  1. https://www.mathworks.com/matlabcentral/answers/332551-matlab-timer-is-not-executed-asynchronously
  2. https://www.mathworks.com/matlabcentral/answers/414967-how-to-execute-timer-functions-in-matlab-gui-in-parallel
Hope this helps!

Categorías

Más información sobre Introduction to Installation and Licensing en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by