bronto@cooper:~/Lab/gravity/tutorial-2$ ./worker.pl & ./worker.pl &
[1] 8079
[2] 8080
bronto@cooper:~/Lab/gravity/tutorial-2$ ./new_task.pl 5
Message "This task will last for 8 seconds" sent to queue gravity.checks
Message "This task will last for 2 seconds" sent to queue gravity.checks
Message "This task will last for 6 seconds" sent to queue gravity.checks
Message "This task will last for 8 seconds" sent to queue gravity.checks
Message "This task will last for 6 seconds" sent to queue gravity.checks
Worker 8080: Received from queue gravity.checks: This task will last for 8 seconds
Worker 8079: Received from queue gravity.checks: This task will last for 2 seconds
bronto@cooper:~/Lab/gravity/tutorial-2$ Worker 8079: Work done in 2 seconds
Worker 8079: Received from queue gravity.checks: This task will last for 6 seconds
Worker 8080: Work done in 8 seconds
Worker 8080: Received from queue gravity.checks: This task will last for 8 seconds
Worker 8079: Work done in 6 seconds
Worker 8079: Received from queue gravity.checks: This task will last for 6 seconds
Worker 8079: Work done in 6 seconds
Worker 8080: Work done in 8 seconds
bronto@cooper:~/Lab/gravity/tutorial-2$ kill %1 %2
bronto@cooper:~/Lab/gravity/tutorial-2$
[1]- Terminated ./worker.pl
[2]+ Terminated ./worker.pl
bronto@cooper:~/Lab/gravity/tutorial-2$

Note that:

only one call of consume() is needed, you don't have to repeat it before each recv();

recv() is blocking, the workers don't stop running when the queue was empty: I had to kill the workers to stop them.

Follow me on Twitter

Meta

Disclaimer

The postings on this site are my own and don't necessarily represent my employer's positions, strategies or opinions!!!

The original contents of this blog (posts, photos,... anything created by the author) are (C) Copyright Marco Marongiu, 2010-2018. Unless a different license is specified in the entry's body, the following license applies: "Verbatim copying and distribution of this entire article is permitted in any medium without royalty provided this notice is preserved and appropriate attribution information (author, original site, original URL) is included".