<div dir="auto"><div><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Hairy Pixels <<a href="mailto:genericptr@gmail.com">genericptr@gmail.com</a>> schrieb am Sa., 17. Sep. 2022, 16:38:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
<br>
> On Sep 17, 2022, at 7:40 PM, Sven Barth <<a href="mailto:pascaldragon@googlemail.com" target="_blank" rel="noreferrer">pascaldragon@googlemail.com</a>> wrote:<br>
> <br>
> It seems you haven't read the part about capturing variables in my announcement mail, cause you have two problems:<br>
> First the specific problem your code has: i is a global variables and global variables are *never* captured, because they don't need to.<br>
> But even if you'd change your code so that the threads are initialized inside a procedure instead of the main block this would still not work, because variables are captured *by reference* which means that i would be shared between all newly created threads plus the main thread and depending on how the threads are scheduled the main thread will reach the call to WaitFor where i will again start from 0.<br>
<br>
I didn’t know they were captured by reference! Does this mean they’re essentially pointers pointing the same variable?</blockquote></div></div><div dir="auto"><br></div><div dir="auto">Then you didn't read my announcement mail deeply enough, cause it's mentioned there! </div><div dir="auto">And they are not pointers, but the variable is moved to an object instance which implements the interface of the function reference. </div><div dir="auto"><br></div><div dir="auto"><br></div><div dir="auto"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Even so I’m trying now to modifying the example by copying to a local variable but I still see this same behavior suggesting there isn’t actually a copy. Why is this?<br></blockquote></div></div><div dir="auto"><br></div><div dir="auto">When your callback is executed i might already have been changed! </div><div dir="auto"><br></div><div dir="auto">Regards, </div><div dir="auto">Sven </div></div>