フィルターのクリア

Running two loop together at the same time

14 ビュー (過去 30 日間)
dsq dq
dsq dq 2021 年 8 月 19 日
回答済み: Raymond Norris 2021 年 8 月 19 日
Hey everyone !
I am currently trying to run the two while loops at the exact same time. When the user click on a button I would like somethings like this to happen :
function start_Callback(hObject, eventdata, handles)
while
xxxx
end
while
xxxxxx
end
I would like this two while loop to run together (I hope it's understandable ^^' ). I dind't find the solution to my problem on the forum, so sorry if it has already been asked ....
Thanks you very much for your anwser !

採用された回答

Raymond Norris
Raymond Norris 2021 年 8 月 19 日
Try using parfeval, such as the following pseudo code
function start_Callback(hObject, eventdata, handles)
pool = gcp('nocreate');
if isempty(pool)
% Explictily start a 2-worker pool
pool = parpool('local',2);
end
f1 = pool.parfeval(@while1,...);
f2 = pool.parfeval(@while2,...);
A couple of notes
  1. You might want to start a pool elsewhere or with a different size.
  2. You'll need to refactor your while-loops as "units of work". That is, write them as subfunctions that can be called on their own. Look at the parfeval doc for additional arguments required (input/output, etc.).
  3. After spawning the code, you might need to cancel the tasks.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeScripts についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by