Sonjli 6 Posted June 12, 2020 Hi, I have a small task where I use this technique: CreateTask( procedure(const Task: IOmniTask) var lPlugObject: IPluggable; begin ... lPlugObject := FPlugProtocolFactory(lTaskPlugAndParams); // Can I use this? lPlugObject.Stoppable := function: Boolean begin result := Task.Terminated or Task.CancellationToken.IsSignalled; end; lPlugObject.Connect; lPlugObject.Run; ... end) ... The PlugObject has an infinite loop inside the Run method, and sometimes it checks the mothod "Stoppable". PlugObject is a plain object without threads or task, only a "repeat until false" loop. I need to know if this use of anonymous can create problems with the threading concurrency in some way. Thanks, Eddy Share this post Link to post
Primož Gabrijelčič 223 Posted June 13, 2020 I see no obvious reasons why this could cause problems. IOW, I think it should work, yes. 1 Share this post Link to post
Stefan Glienke 2018 Posted June 16, 2020 Only testing the code yourself will show but I can smell a potential memory leak due to circular references caused by anonymous methods and capturing of the IOmniTask within itself - nested anonymous methods can be a bit nasty sometimes. 1 Share this post Link to post
Sonjli 6 Posted June 17, 2020 4 hours ago, Stefan Glienke said: Only testing the code yourself will show but I can smell a potential memory leak due to circular references caused by anonymous methods and capturing of the IOmniTask within itself - nested anonymous methods can be a bit nasty sometimes. Yes, in my tests I found some strange behaviours within the omnitask and reference counting, very hard to explain and to test. But after days of pain I found the problem, and I am pretty sure it is not related to Omni or Spring. I am writing a microservices framework with mqtt using a library with some problems with threading... Thanks and keep up the good job Eddy Share this post Link to post