Re: Stack and Thread Safety

From: Chris Smith (cdsmith_at_twu.net)
Date: 06/30/04


Date: Wed, 30 Jun 2004 08:07:42 -0600

Sebastian Scheid wrote:
> No you cannot. Stack could have thread unsafe parts in it. But in fact it
> has not. Its methods are synchronized. So Stack is threadsafe but not
> because in extends Vector!

It's worth pointing out here that "thread-safe" is a rather vague term
here. To reason about correctness of a multithreaded program, you need
to do more than ask if everything you use is "thread-safe". For
example, if I needed to push three values consecutively onto a stack,
I'd still need to take out a monitor on that stack to ensure that the
set of tree push operations are atomic.

-- 
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.
Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation


Relevant Pages

  • Re: Thread-safety and Singleton methods
    ... Why wouldn't static methods be thread-safe? ... instance of the singleton class) then of course if you change it once it'll ... > Parameters are passed to a method using a stack. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Thread-safe fuctions
    ... > a program is reentrant if more than one user can run it ... stronger concept that just "thread-safe". ... data (or does so with the necessary protections), ... > functions to occupy the same position on the stack) ...
    (comp.unix.programmer)
  • Thread-safety and Singleton methods
    ... read many posts on this topic but not clear about this and hence I am posting ... public methods in that class be thread-safe? ... they say that singleton class methods are thread-safe...I request you to ... Parameters are passed to a method using a stack. ...
    (microsoft.public.dotnet.framework.aspnet)