Releases: pmmp/ext-pmmpthread
6.0.5
6.0.4
6.0.3
6.0.2
6.0.1
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.
6.0.0-beta1
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.
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.
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.
5.3.1
- Fixed edge case with nested thread-safe objects that could lead to avoidable
ThreadedConnectionException
s being thrown. - Improved performance of dereferencing thread-safe objects from another thread by avoiding useless internal allocations. This reduces overhead for things like
Worker
.
5.3.0
Changes since 5.2.x
This release mainly focuses on improving closure behaviour, and imposing clear restrictions.
Behaviour changes
- Thread-safe objects can no longer be serialized. Previously, they would serialize to a pointer, which was useless aside from the old serialize hacks used by pthreads v4 and earlier.
- Closures with a non-thread-safe
$this
can no longer be assigned to thread-safe objects. Previously,$this
would be silently removed.- Tip: Use
static function
orstatic fn
to prevent$this
being bound to closures when you don't need it.
- Tip: Use
- Closures with a thread-safe
$this
will now have$this
restored when copying a closure out onto a new thread (as you would expect). Previously,$this
was never copied. - Closures with static variables (e.g.
static $var;
) can no longer be assigned to thread-safe objects. This is because their values can change in ways that pthreads can't track, making it impossible to make their behaviour predictable.- To persist closure state in a thread-safe manner, consider
use()
ing a thread-safe object into the closure instead of using static variables.
- To persist closure state in a thread-safe manner, consider
- Closures with use-by-reference can no longer be assigned to thread-safe objects. This is because references can't be updated from a different thread, making it impossible to give them intuitive behaviour.
Please note that the behaviour of closures may still change as the desired behaviour is finalized before the 6.0.0 release.
Fixes
- Repeatedly passing the same closure from one thread to another no longer causes a memory leak on the receiving thread, thanks to improvements in closure definition vs instance handling.
- Fake closures (first-class callables, or closures created using
Closure::fromCallable()
) now share the static variables of the original function in 8.1 and up when copied between threads, as a non-copied closure would. ThreadedArray::merge()
now throws better exceptions when attempting to merge non-thread-safe elements.- Fixed
Unsupported data type callable
when attempting to useThreadedArray::merge()
with an object containing unmodified typed properties (improper IS_INDIRECT handling). - Fixed bogus "access before initialization" errors being generated when attempting to assign a reference to a thread-safe object.
5.2.4
Changes since 5.2.3
- Fixed segfault when synchronizing an object containing a thread-safe object destroyed by another thread.
- Fixed segfault on thread shutdown when the owner of a resource unsets it from a thread-safe object property.
- Reduced allocations in thread-safe property storage, which should improve performance.
- Remove useless property table rebuild when writing a thread-safe object to a property of another thread-safe object.
- Fixed assert failure when using
ReflectionObject->getProperties()
on aThreadedArray
which was only modified using[]=
. - Cleaned up code in some areas, fixing a bunch of compiler warnings.
- Added missing get_gc handler for iterators.