Re: Generators and Yield-- persuasive tools from Python &c.
Posted: Mon Apr 25, 2016 9:05 am
StefanoLanzavecchia wrote:So, this:{⎕tget ⍵}&¨⍳60
doesn't create OS threads nor consumes visible CPU time.
This:{⎕tget ⍵}&¨⍳61
doesn't create OS threads but it saturates a CPU core.
I repeat: if I had noticed this behaviour before, I cannot remember now. But it looks like a somewhat serious limitation to the usage of []T's.
Is it related to the fact that WaitForMultipleObjects can only wait for a maximum of 64 object handles? (Constant MAXIMUM_WAIT_OBJECTS is 64).
By the way: I tried all my experiments using the 32 bits, classic version of the Windows interpreter. Right now I have no means (nor much interest to be honest :-)) to test on different OSes.
Yes, it's that. The interpreter attempts to use semaphores where it can to reduce CPU usage with multiple threads. There are techniques to wait on more that 64 handles, but currently the interpreter doesn't use them. I suspect that in some case the process of generating the list of semaphores may consume more CPU than just letting the thread switch process occur,and this may become more true if we support a larger number of semaphores. Of course, it's hard to confirm that.