PocketMine-MP icon indicating copy to clipboard operation
PocketMine-MP copied to clipboard

Remove `ThreadManager`

Open dktapps opened this issue 2 years ago • 0 comments

Description

The only remaining uses for ThreadManager are:

  • Providing thread count - inaccurate if threads start more threads, can be better provided by ext-pmmpthread directly
  • Stopping threads which haven't stopped themselves - mostly pointless
    • threads will join themselves when __destruct()'d under normal circumstances, which ThreadManager actually interferes with by keeping strong references
    • on-shutdown thread stopping can be implemented by overriding join() which will be called directly by ext-pmmpthread during __destruct()
  • Simulating detach() and/or leaking threads - not a particularly useful case, and can also be simulated more intentionally by implementing detach() in ext-pmmpthread directly
  • Delaying automatic attempts to stop threads to allow ServerKiller functionality to work - not sure how to replace or remove this

In addition:

  • Even if it did track threads started by other threads, we wouldn't actually want ThreadManager to try and stop them, because the parent of a thread can't be join()'d before its children are also join()'d. At best we would want to stop them in reverse order, which it's never done.

TL;DR: ThreadManager no longer serves a useful purpose, and is actually probably detrimental in some cases.

dktapps avatar Dec 20 '23 17:12 dktapps