{"action":"created","issue":{"url":"https://api.github.com/repos/GarageGames/Torque3D/issues/1174","labels_url":"https://api.github.com/repos/GarageGames/Torque3D/issues/1174/labels{/name}","comments_url":"https://api.github.com/repos/GarageGames/Torque3D/issues/1174/comments","events_url":"https://api.github.com/repos/GarageGames/Torque3D/issues/1174/events","html_url":"https://github.com/GarageGames/Torque3D/issues/1174","id":57100543,"number":1174,"title":"pool->flushWorkItems(); may not work.","user":{"login":"lukaspj","id":2369614,"avatar_url":"https://avatars.githubusercontent.com/u/2369614?v=3","gravatar_id":"","url":"https://api.github.com/users/lukaspj","html_url":"https://github.com/lukaspj","followers_url":"https://api.github.com/users/lukaspj/followers","following_url":"https://api.github.com/users/lukaspj/following{/other_user}","gists_url":"https://api.github.com/users/lukaspj/gists{/gist_id}","starred_url":"https://api.github.com/users/lukaspj/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lukaspj/subscriptions","organizations_url":"https://api.github.com/users/lukaspj/orgs","repos_url":"https://api.github.com/users/lukaspj/repos","events_url":"https://api.github.com/users/lukaspj/events{/privacy}","received_events_url":"https://api.github.com/users/lukaspj/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-02-09T22:32:05Z","updated_at":"2015-02-09T23:21:36Z","closed_at":null,"body":"I was doing some multithreading on the particlesystem, the code can be found [here](https://gist.github.com/lukaspj/448c8910951ad6f4c232#file-particlethreading-cpp-L3-L11).\r\n\r\nBut I encountered an issue when there were several threads running, adding some debug info, I got this in the console:\r\n```\r\nCreated queue\r\nFinished a Particle Worker Thread\r\nFinished a Particle Worker Thread\r\nFinished a Particle Worker Thread\r\nFinished a Particle Worker Thread\r\nDeleting queue\r\nDeleted queue\r\nCreated queue\r\nFinished a Particle Worker Thread\r\nFinished a Particle Worker Thread\r\nFinished a Particle Worker Thread\r\nDeleting queue\r\nFirst-chance exception at 0x10E818EC (Empty_DEBUG DLL.dll) in Empty_DEBUG.exe: 0xC0000005: Access violation reading location 0xFEEEFEF6.\r\nDeleted queue\r\n```\r\n\r\nAs you can see, in the last pass, it deletes the queue before all the threads have finished, afaik `pool->flushWorkItems();` should ensure that all the threads have finished.\r\n\r\nThis is the main code that triggers this issue:\r\n```c++\r\n   OutputDebugStringA(\"Created queue\\n\");\r\n   ParticleQueue* queue = new ParticleQueue(mParticlePool->GetParticleHead()->next);\r\n   ThreadPool* pool = &ThreadPool::GLOBAL();\r\n\r\n   F32 t = F32(ms) / 1000.0;\r\n\r\n   for (U32 i = 0; i < 4; ++i)\r\n   {\r\n      ThreadSafeRef< ParticleUpdateItem > item(new ParticleUpdateItem(queue, t, this, BHVs));\r\n      pool->queueWorkItem(item);\r\n   }\r\n\r\n   pool->flushWorkItems();\r\n\r\n   OutputDebugStringA(\"Deleting queue\\n\");\r\n   delete queue;\r\n   OutputDebugStringA(\"Deleted queue\\n\");\r\n```"},"comment":{"url":"https://api.github.com/repos/GarageGames/Torque3D/issues/comments/73612788","html_url":"https://github.com/GarageGames/Torque3D/issues/1174#issuecomment-73612788","issue_url":"https://api.github.com/repos/GarageGames/Torque3D/issues/1174","id":73612788,"user":{"login":"lukaspj","id":2369614,"avatar_url":"https://avatars.githubusercontent.com/u/2369614?v=3","gravatar_id":"","url":"https://api.github.com/users/lukaspj","html_url":"https://github.com/lukaspj","followers_url":"https://api.github.com/users/lukaspj/followers","following_url":"https://api.github.com/users/lukaspj/following{/other_user}","gists_url":"https://api.github.com/users/lukaspj/gists{/gist_id}","starred_url":"https://api.github.com/users/lukaspj/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lukaspj/subscriptions","organizations_url":"https://api.github.com/users/lukaspj/orgs","repos_url":"https://api.github.com/users/lukaspj/repos","events_url":"https://api.github.com/users/lukaspj/events{/privacy}","received_events_url":"https://api.github.com/users/lukaspj/received_events","type":"User","site_admin":false},"created_at":"2015-02-09T23:21:36Z","updated_at":"2015-02-09T23:21:36Z","body":"Yeah that was simply it, sorry for bothering you, but this whole thing is not exactly perfectly described :)"}}