Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between Thread Object and Worker Object (php pthreads)

The only explanation that I've found so far is here: http://pthreads.org

But what does that mean in terms of code? When should I use Worker(s) and where should I use Threads?

Thanks!

like image 864
Pavel Avatar asked Dec 27 '22 05:12

Pavel


1 Answers

They are both Threads, but, a Thread is intended to execute one task ( that defined in it's run method ) and then exit. A Worker is intended to wait for tasks, in the form of Stackable derived objects, implementing their own run methods and execute them from a stack in the order they are inserted.

In this way, the Worker allows you to reuse a context, they provide a means of efficiency quite difficult to program in userland, but nothing like impossible.

like image 124
Joe Watkins Avatar answered May 07 '23 11:05

Joe Watkins