Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign up[Core] ThreadPool: shutdown idle threads #302
Conversation
This comment has been minimized.
This comment has been minimized.
Also, we just ignore exceptions created by the delegates it runs, shouldn't we handle them in some way ? |
This comment has been minimized.
This comment has been minimized.
Yes I also noticed this exception swallowing when we discussed about it in Discord channel, not good... Any proposal? PS: Let me know if you prefer to merge this one first and do exception later in a separate PR, or deal with it as part of this PR. |
This comment has been minimized.
This comment has been minimized.
Also concerning synchronization, please keep the This is highly performance critical (we use that for microtasks and spawn hundreds of them per frame). |
|
||
if (activeThreadCount + 1 >= workers.Count && workers.Count < maxThreadCount) | ||
var curWorkingCount = Interlocked.CompareExchange(ref workingCount, 0, 0); | ||
var curAliveCount = Interlocked.CompareExchange(ref aliveCount, 0, 0); |
This comment has been minimized.
This comment has been minimized.
xen2
Jan 18, 2019
Member
@Kryptos-FR I think it looks confusing.
I would say, let's go back to a more simple version (while making sure each var is read only once):
var curAliveCount = aliveThreadCount;
if (workingCount + 1 >= curAliveCount && curAliveCount < maxThreadCount)
This comment has been minimized.
This comment has been minimized.
BTW I can think of at least one race condition & potential deadlock: If all threads are finishing, and they are after the while loop but before the Probably unlikely, but multithreading program often tend to have those worst case you think are never possible once in a while given enough time :) (esp. since all the threads might be started at approx the same time) |
This comment has been minimized.
This comment has been minimized.
I could also compute the result of the time delta comparison outside of the spinlock, might as well trade some precision with shorter spinlock duration, what do you guys think ? |
This comment has been minimized.
This comment has been minimized.
@Eideren |
This comment has been minimized.
This comment has been minimized.
I wasn't as clear as I should have, here's what I meant in my previous message |
This comment has been minimized.
This comment has been minimized.
@Eideren OK got it, looks good to me! |
…double->long conversion)
This comment has been minimized.
This comment has been minimized.
Merged, thanks! |
Eideren commentedDec 27, 2018
ThreadPool never close off the threads it spawns, see Discord discussion for more details.
@Kryptos-FR I did a couple of changes, how would you deal with synchronization ?