That is correct, sir. It is logic that sleeping (using the OS), should allow for CPU to carry out more work on other threads. The question was whether or not the yield() before or after helps in any way and how yield is implemented in *nix systems with a typical vanilla Perl binary distro.
To add a bit more context: The program is a scanning and OMR (Optical Mark Recognition aka Bubble Test) corrector. So while the scanner is fetching pages and transmitting images over the USB wire, the OMR lib is processing and decoding. The scanning thread waits for an image queue to be emptied by the OMR thread before fetching for the new image. Threading alone, reduced total processing time to about one third (3 seconds down to a bit over 1 - on average).
Initially, I just added the millisecond delay so I don't hog the CPU looping on the $image_queue->pending call while the OMR thread clears the queue. I could have used 2 queues and fully sync both threads with a $queue->dequeue on the scanning thread, but the program as whole is really complex so I refrain from adding new things unless absolutely necessary.
What I was doubtful about, was if adding a yield() before or after the the delay would aid the OS somehow in yielding more CPU time to other threads of the same parent PID. Carrying out different tests it really makes no difference on my single CPU laptop (though the delay alone does help!). I will carry more test on dual-core CPUs and see if it makes any difference. But if not, what is the yield() call there for? It just calls a single no-op? What's the use of single no-op? Does it do anything more interesting on other OSs/Configurations? Can it be compiled to do anything more interesting than a single no-op?
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.