ext-pmmpthread
ext-pmmpthread copied to clipboard
Thread & Worker should not be ThreadSafe objects
It doesn't really make any sense for these objects to be shared.
They contain API methods which are only intended for the parent thread to use, such as start(), join(), isRunning(), isJoined(), etc.
The only reason a shared context object is desirable for these things is to allow Thread::run() to get information from the parent thread.
After the initial run(), it makes more sense to put things in static properties, rather than paying a performance penalty to access them from the thread context again and again.
Proposal:
- Make
ThreadandWorkerno longer extendThreadSafe - Make
ThreadandWorkerbecomefinal - Make
Threadaccept aRunnablein its__construct()(which will be thread-safe), which it runs and then immediately shuts itself down (contrary to aWorker, which remains running - though we could easily ditchThreadand only haveWorkerwith this system) - Possibly introduce
ClosureRunnable - Move
Thread::getCreatorId()toRunnable::getCreatorId() - Remove
Thread::getCurrentThread()andThread->getThreadId()(Thread::getCurrentThreadId()will remain) - Add
Thread::getName()andThread::setName()for identification (relates to #139)