Re: Multi-Threading Question



- <a@xxxxxxx> wrote:
> Local variables are always thread-safe, since they are not shared among
> threads. This is because each thread has its own stack (where the local
> variables are stored).

That's certainly true. However, if the local variable is a reference to
an object which is also being used and potentially changed on another
thread, you need to use locks, volatile variables or explicit memory
barriers to ensure safety.

--
Jon Skeet - <skeet@xxxxxxxxx>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
.



Relevant Pages

  • Re: try finally Error Handling without catch
    ... exceptions thrown in the try block are still propagated up the stack ... Jon Skeet - ... If replying to the group, please do not mail me too ... Prev by Date: ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: [2.6 patch] i386: always use 4k stacks
    ... but for real production you want a safety ... That's simple because there are likely some code paths through ... Map a blank ro page beneath the address range when stack memory is ... send the line "unsubscribe linux-kernel" in ...
    (Linux-Kernel)
  • Re: [9fans] Van Jacobsens network stack restructure
    ... >> Plan 9 IP stack doesn't seem to have the lineage of the linux and bsd ... >> "They who can give up essential liberty for temporary ... >> safety, ... --Benjamin Franklin ...
    (comp.os.plan9)
  • Re: [9fans] Van Jacobsens network stack restructure
    ... > Plan 9 IP stack doesn't seem to have the lineage of the linux and bsd ... i am not intimate with the IP stack code, ... > "They who can give up essential liberty for temporary ... > safety, ...
    (comp.os.plan9)
  • Re: [2.6 patch] i386: always use 4k stacks
    ... > on the stack) and if x86 allows stackbloat, ... but for real production you want a safety ... the code that need more stack space and that are rarely hit (and ... send the line "unsubscribe linux-kernel" in ...
    (Linux-Kernel)