I have a system that relies on an event, and to speed up the system I tried to parallelize it, however events don't seem to trigger in parallel loops. Since my system is too large I have it boiled down into about 30 lines here (3 files)
classdef eventsend < handle
events
go
end
methods
function sendit(self)
notify(self,'go');
end
end
end
classdef eventcatch
methods
function self = eventcatch(sender)
addlistener(sender,'go',@self.doSomething);
end
function doSomething(varargin)
disp('HERE');
end
end
end
function bug
send = eventsend();
eventcatch(send);
a = @send.sendit;
a();
parfor i=1:5
a();
end
end
This will print HERE once, but if the par is removed it will work and print 6 times.
Question: Is there a way I can parallelize it and still have events?