Capturing by value in the thread

mzfhhhh mzfhhhh at foxmail.com
Sat Oct 19 03:36:38 UTC 2024


On Friday, 18 October 2024 at 12:07:24 UTC, Kadir Erdem Demir 
wrote:
> It seems [=] functionality C++ does not exist in D.
> By using a helper function I made that example work.
>
> [...]

Because 'work' is captured, it is allocated on the heap.
The loops are all assigning values to this 'work' in the heap.

The values in front of 'work' are all overwritten,
so after the thread runs, it prints the last value.


More information about the Digitalmars-d-learn mailing list