On Wed Jul 27 17:31:54 2022 +0000, Piotr Caban wrote:
I would like to see the tests for finishing the main thread while task collection is still executing. I'm not saying that code like yours will not work. I'm saying that you shouldn't write anything like this while programming in C++. If it's really needed, it should be done by different class that creates and destroys the class (manages it's lifetime). And the only sensible place I can see now is the scheduler class. I really doubt that anything like ref-counting is done in native implementation.
@piotr
So actually how many contexts are reused seems to somehow depend on how many CPUs there are. [msvcr120.c.diff](/uploads/b72cf9ede1319ae6cea220e76aead265/msvcr120.c.diff)
Output with a 12 core 24 thread VM: ``` context: 000001EFC5C80A80 id 1 context: 000001EFC5C81CB0 id 2 context: 000001EFC5C97DE0 id 8 context: 000001EFC5C99A70 id 9 context: 000001EFC5C99810 id 10 context: 000001EFC5C996E0 id 11 context: 000001EFC5C99220 id 12 context: 000001EFC5C99350 id 13 context: 000001EFC5C98D60 id 14 context: 000001EFC5C995B0 id 15 context: 000001EFC5C99940 id 16 context: 000001EFC5C98E90 id 17 context: 000001EFC5C98E90 id 17 context: 000001EFC5C99940 id 16 context: 000001EFC5C995B0 id 15 context: 000001EFC5C98D60 id 14 context: 000001EFC5C99350 id 13 context: 000001EFC5C99220 id 12 context: 000001EFC5C996E0 id 11 context: 000001EFC5C99810 id 10 context: 000001EFC5C99A70 id 9 context: 000001EFC5C97DE0 id 8 context: 000001EFC5C81CB0 id 2 context: 000001EFC5C80A80 id 1 1c64:msvcr120: 897 tests executed (0 marked as todo, 0 failures), 0 skipped. ```
Output with a 2 core 4 thread VM: ``` context: 000001C04031D100 id 2 context: 000001C04031E210 id 1 context: 000001C040332580 id 7 context: 000001C0403320C0 id 8 context: 000001C0403321F0 id 9 context: 000001C040331D30 id 10 context: 000001C0403327E0 id 11 context: 000001C040331E60 id 12 context: 000001C040332320 id 13 context: 000001C040331C00 id 14 context: 000001C0403326B0 id 15 context: 000001C040331F90 id 16 context: 000001C0403320C0 id 8 msvcr120.c:1768: Test failed: context changed context: 000001C040332580 id 7 msvcr120.c:1768: Test failed: context changed context: 000001C04031E210 id 1 msvcr120.c:1768: Test failed: context changed context: 000001C04031D100 id 2 msvcr120.c:1768: Test failed: context changed context: 000001C0403327E0 id 17 msvcr120.c:1768: Test failed: context changed context: 000001C040332910 id 18 msvcr120.c:1768: Test failed: context changed context: 000001C0403321F0 id 19 msvcr120.c:1768: Test failed: context changed context: 000001C040331F90 id 20 msvcr120.c:1768: Test failed: context changed context: 000001C040331E60 id 21 msvcr120.c:1768: Test failed: context changed context: 000001C040331D30 id 22 msvcr120.c:1768: Test failed: context changed context: 000001C0403326B0 id 23 msvcr120.c:1768: Test failed: context changed context: 000001C040332320 id 24 msvcr120.c:1768: Test failed: context changed 2630:msvcr120: 897 tests executed (0 marked as todo, 12 failures), 0 skipped. ```
If I increase the `THREAD_COUNT` I get failures too with 12 cores 24 threads. No idea yet why it chooses physical cores in the first case and logical cores in the second case.
How do you think I should implement this behavior?