Stack and Thread Safety  
Author Message
Kenneth P. Turvey





PostPosted: 2004-6-30 7:57:00 Top

java-programmer, Stack and Thread Safety May I assume that a stack is thread safe since it extends the
synchronized vector class?

Thanks.

--
Kenneth P. Turvey <email***@***.com>

Artificial Intelligence Algorithms Wiki
http://ai.squeakydolphin.com
 
Sebastian Scheid





PostPosted: 2004-6-30 20:41:00 Top

java-programmer >> Stack and Thread Safety
"Kenneth P. Turvey" <email***@***.com> schrieb im Newsbeitrag
news:email***@***.com...
> May I assume that a stack is thread safe since it extends the
> synchronized vector class?

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!

Sebastian


 
Chris Smith





PostPosted: 2004-6-30 22:08:00 Top

java-programmer >> Stack and Thread Safety 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
 
 
Kenneth P. Turvey





PostPosted: 2004-7-1 7:33:00 Top

java-programmer >> Stack and Thread Safety On Wed, 30 Jun 2004 08:07:42 -0600, Chris Smith <email***@***.com> wrote:
> Sebastian Scheid wrote:
>
> 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.

I understand the complexities of the problem. I was only doing a
single pop from the stack in each thread. Thanks for the help.


--
Kenneth P. Turvey <email***@***.com>

Artificial Intelligence Algorithms Wiki
http://ai.squeakydolphin.com