79220624

Date: 2024-11-24 16:57:22
Score: 1
Natty:
Report link

The myStruct variable in your test() function is scoped to that function. When you change it after the await, you are modifying the same local variable, even if it runs on a different thread. Each thread does not have its own separate instance of myStruct; they operate on the same function context, but the value type's nature ensures that if you were to pass it to another context, it would be copied rather than shared.

So, to answer your question directly: the myStruct that you are modifying after the sleep is the same instance (in terms of the function's scope) that was created at the beginning of the function. It does not create a separate instance for the background thread; it simply continues to operate on the local variable in that function.

Reasons:
  • Long answer (-0.5):
  • No code block (0.5):
  • Low reputation (1):
Posted by: Lukshya Supyal