Skip to content

6.0.0

Compare
Choose a tag to compare
@dktapps dktapps released this 22 May 21:29
· 118 commits to fork since this release
12cd4af

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 to Thread::INHERIT_* class constants.
  • Thread::start() now requires the $options parameter to be specified. INHERIT_NONE should be preferred for large applications, while INHERIT_ALL will likely be necessary for small test scripts.
  • Added Thread::getSharedGlobals() : ThreadSafeArray, which returns a ThreadSafeArray 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 to Workers. This can be done using Thread::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 of ThreadSafe.

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.
  • Workers no longer accept tasks after shutdown.
  • Workers 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.
  • Workers no longer accept tasks if an error occurred during execution.
  • Fixed some auto globals being armed multiple times, causing performance losses during thread start.