6.0.0
This major version renames the extension from pthreads
to pmmpthread
, refactors and renames some classes, and generally cleans up some magic stuff leftover from v5.
The overall system architecture is mostly the same as v5. This version mostly differs in terms of the API it presents.
If you're upgrading from v4, please see docs/UPGRADING_4.x_to_6.0.md.
Changes since 5.x
General
- PHP 8.1 is now required. 8.0 was dropped due to various inconsistencies and bugs.
- Extension has been renamed to
pmmpthread
.- This change allows the extension to be potentially submitted to PECL as well as submitting stubs for jetbrains/phpstorm-stubs.
- In theory, it should also be able to coexist with previous pthreads versions, but I don't recommend trying to load both at the same time.
API changes
- All classes have been moved to the
pmmp\thread
namespace. - The following classes have been renamed:
ThreadedBase
->pmmp\thread\ThreadSafe
ThreadedArray
->pmmp\thread\ThreadSafeArray
ThreadedRunnable
->pmmp\thread\Runnable
ThreadedConnectionException
->pmmp\thread\ConnectionException
Thread
->pmmp\thread\Thread
Worker
->pmmp\thread\Worker
PTHREADS_INHERIT_*
constants have been moved toThread::INHERIT_*
class constants.Thread::start()
now requires the$options
parameter to be specified.INHERIT_NONE
should be preferred for large applications, whileINHERIT_ALL
will likely be necessary for small test scripts.- Added
Thread::getSharedGlobals() : ThreadSafeArray
, which returns aThreadSafeArray
automatically available to all threads. - Resources are no longer considered thread-safe values, and are no longer accepted as properties of any
ThreadSafe
object. - Removed magic
worker
field declared on task classes submitted toWorker
s. This can be done usingThread::getCurrentThread()
instead. - Class static property default values are now always used by inherited classes. This was previously inconsistent when OPcache was used, as property defaults would inconsistently be mixed with property values copied from the parent thread at the time of thread creation.
pmmp\thread\NonThreadSafeValueError
is now thrown when attempting to assign any non-thread-safe value to a property or offset ofThreadSafe
.
Fixes
- Fixed memory leak when connecting
Runnable
objects for execution. ThreadSafeArray
(ThreadedArray
) no longer supports property operations (these were previously proxied to array offset write operations by mistake). Now, an error is generated instead.Worker
s no longer accept tasks after shutdown.Worker
s now terminate themselves if a task encounters a fatal error. Previously, a task could cause a fatal error (e.g. by leaking memory), and the worker would stay alive in a broken state, with no way for the parent thread to know there was a problem.Worker
s no longer accept tasks if an error occurred during execution.- Fixed some auto globals being armed multiple times, causing performance losses during thread start.