Info
Questa domanda è chiusa. Riaprila per modificarla o per rispondere.
Two classes being executed at the same time, sharing information
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Hello everybody
I have two classes, A and B, being B a property of A. B is continuously making some calculations, with its own pace, while A is making others. At some point, A requests information to B. This would be a simplification of both classes:
A:
classdef AClass
properties
B
end
methods
function obj = AClass()
B = BClass();
while true
count = B.getCount;
disp(['Count now: ',num2str(count)])
pause(2)
end
end
end
end
B:
classdef BClass
properties
count = 0
end
methods
function obj = BClass()
while true
obj.count = obj.count + 1;
pause(1)
end
end
function output = getCount(obj)
output = obj.count;
end
end
end
Of course executing AClass does not work as it would be expected, since it gets stuck in the while loop, inside B. I was wondering if there is a way of making it work.
For instance in ROS (Robot Operating System), it would be pretty easy. A would be executed in a node and B in another, and each time A needs the information from B, either it is subscribed to a topic or uses a service.
Thanks a lot in advance
0 Commenti
Risposte (0)
Questa domanda è chiusa.
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!