comp.lang.ada
 help / color / mirror / Atom feed
From: Jim Rogers <jimmaureenrogers@worldnet.att.net>
Subject: Re: ada paper critic
Date: Sun, 16 Jun 2002 15:07:03 GMT
Date: 2002-06-16T15:07:03+00:00	[thread overview]
Message-ID: <3D0CA980.5050505@worldnet.att.net> (raw)
In-Reply-To: aehq64$71cp5$1@ID-77047.news.dfncis.de

> Darren New wrote:
> 
> 
>>"Dmitry A. Kazakov" wrote:
>>
>>>Actually I meant Ada's protected objects and not the visibility rules.
>>>There is a great need to have protected objects extensible (tagged).
>>>At the same time it is not very clear (at least to me), how to do it.
>>>
>>What's wrong with Java's approach to OO threading and protected objects?
>>


There are actually a number of problems with Java's approach to OO
threading and protected objects.

The first problem is that Java does not have protected objects in the
Ada sense of the term. Java only provides synchronization blocks, which
are not even close to being protected objects.

Java's threading model works very well as long as your threads do not
communicate with each other, and they never need to be terminated.
Of course, many useful concurrent designs do need to have
communication between tasks, and those tasks need to be terminated
as some point in the program.

The only safe communication feature for Java threads is synchronized
blocks. The code in the synchronized block belongs to the shared
object. That object might be one of the threads, or a shared object.

Let's look at a classical concurrent design, the producer/consumer
model. Any decent threading implementation should be able to
properly support a producer/consumer model. Let's assume that our
application needs reliable communication between the producer thread
and the consumer thread. We will use a bounded queue between the
producer and the consumer. The producer must not write to the bounded
queue when it is full, and the consumer must not read from the
bounded queue when it is empty. In Ada this would be handled simply
using a protected object with two entries; one to add elements to
the bounded queue, and one to extract elements from the bounded queue.

In Java you will create your bounded queue class. You will provide two
methods, one to add elements to the queue and one to extract elements
from the queue. Each of these methods must be declared synchronized.

Under Java rules you must call the synchronized block, and obtain the
synchronization lock before you can check for conditions such as
queue full or queue empty. If the producer is calling the add element
method and the queue is full the wait() method must be called to
suspend the producer. Note that the producer class has no control
over this code. It merely calls the method defined in the bounded
queue class. There is no Java equivalent to the Ada timed select
statement allowing an Ada task to limit its suspension time on an
entry call. In Java the producer will be suspended until another
thread, in this case the consumer, calls the notify() or the
notifyAll() method. The notify() method randomly unsuspends one
suspended thread, no matter which synchronization block it is waiting
for. The notifyAll() method unsuspends all suspended threads, forcing
each to check whether or not it should proceed. If not, it must be
immediately re-suspended using a wait() call.

Note that all this re-checking and waiting is still occuring in the
code for the synchronized object, not at all under control of the
producer thread. How do we design this so that the producer can
have an effective timeout on its suspension? We could design the
bounded queue code so that it provides a fixed timeout period for
all threads that may be suspended. The problem here is that this
forces all threads calling this synchronized block to have
the same timing requirements. You could allow the calling thread
to pass a timeout value to the synchronized block. This forces you
to reveal internal state of your thread to another object, violating
encapsulation principles.

Given the behavior of the notify() and the notifyAll() methods there
is no guarantee that a given thread will ever progress past a set
of wait/notify calls to execute the bulk of the synchronized block.
Java provides nothing like an Ada entry queue. Thus, the order in
which threads are unsuspended is not deterministic.

Let's turn now to the issue of terminating a thread. Java provides a
stop() method to terminate a thread. Java has also deprecated the
use of this method because it has been found to be unsafe. The
problem is that the stop() method does not release any synchronization
locks currently held by the thread being stopped. This easily
results in starvation because no other thread will be allowed to
acquire the synchronization lock. The current Java solution is to
require the programmer to invent his own termination method which
some other method will call. Of course, that termination condition
will not be serviced until the "terminated" thread has returned from
all synchronized blocks, which as I have shown above, may never
happen.

Jim Rogers




  reply	other threads:[~2002-06-16 15:07 UTC|newest]

Thread overview: 135+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-06-14  0:49 ada paper critic Immanuel Scholz
2002-06-14  1:28 ` Immanuel Scholz
2002-06-14  1:43   ` Dale Stanbrough
2002-06-14  4:53     ` David Marceau
2002-06-14  6:40       ` Dale Stanbrough
2002-06-14  6:49       ` Hyman Rosen
2002-06-14 12:18       ` Baugereau
2002-06-14 16:30         ` David Marceau
2002-06-14 17:34           ` Baugereau
2002-06-14 19:01             ` Wes Groleau
2002-06-14 19:43               ` Baugereau
2002-06-15  3:02                 ` Vinzent Hoefler
2002-06-15  9:49                   ` Pascal Obry
2002-06-17 15:53                     ` Dan Andreatta
2002-06-17 18:20                       ` Pascal Obry
2002-06-17 20:56                     ` Michael Bode
2002-06-17 21:18                       ` Pascal Obry
2002-06-16 21:52                   ` Ted Dennison
2002-06-14 20:02     ` Immanuel Scholz
2002-06-14  3:14   ` Ted Dennison
2002-06-14  4:35     ` Dale Stanbrough
2002-06-14  8:05       ` David Marceau
2002-06-14 12:31         ` Dale Stanbrough
2002-06-14 15:08         ` Darren New
2002-06-17  0:17           ` Robert A Duff
2002-06-14 19:05         ` Wes Groleau
2002-06-16  3:34           ` Dale Stanbrough
2002-06-16  3:32         ` Dale Stanbrough
2002-06-14  8:25       ` Dmitry A. Kazakov
2002-06-14 12:19         ` Immanuel Scholz
2002-06-14 14:51           ` Dmitry A. Kazakov
2002-06-14 15:09             ` Darren New
2002-06-16 22:49               ` Dmitry A.Kazakov
2002-06-16 15:07                 ` Jim Rogers [this message]
2002-06-17  4:06                   ` Darren New
2002-06-17  4:52                     ` Jim Rogers
2002-06-17  9:45                       ` David Marceau
2002-06-17 15:42                       ` Darren New
2002-06-17  3:59                 ` Darren New
2002-06-17 22:19                   ` Dmitry A.Kazakov
2002-06-14 12:58       ` Larry Kilgallen
2002-06-14 22:16         ` Dale Stanbrough
2002-06-15  1:22           ` Larry Kilgallen
2002-06-15  0:51             ` Dale Stanbrough
2002-06-15 11:49               ` Immanuel Scholz
2002-06-15 21:45             ` Robert A Duff
2002-06-14 14:59       ` Ted Dennison
2002-06-16  3:27         ` Dale Stanbrough
2002-06-16 22:18           ` Wes Groleau
2002-06-16 22:38           ` Ted Dennison
2002-06-14 15:00       ` Ted Dennison
2002-06-14 20:13         ` Wes Groleau
2002-06-14 18:52       ` Jeffrey Carter
2002-06-15 22:03         ` Robert A Duff
2002-06-16  1:58           ` Jeffrey Carter
2002-06-16  3:19             ` Dale Stanbrough
2002-06-16 22:20         ` Wes Groleau
2002-06-17  1:57           ` Larry Kilgallen
2002-06-17  2:16           ` Jeffrey Carter
2002-06-14 15:25   ` John R. Strohm
2002-06-15  4:05     ` Lyle McKennot
2002-06-17 13:32       ` Marin David Condic
2002-06-15  4:06     ` The 1980 ACM Turing Award Lecture The Emperor's Old Clothes Lyle McKennot
2002-06-15 13:45       ` Ted Dennison
2002-06-15 13:55         ` Ed Falis
2002-06-15 15:03           ` Pat Rogers
2002-06-15 18:42         ` Jeffrey Carter
2002-06-16 22:25         ` Wes Groleau
2002-06-15 18:01       ` Robert I. Eachus
2002-06-16  1:53         ` Hyman Rosen
2002-06-17 20:06           ` Robert I. Eachus
2002-06-17 20:54             ` Hyman Rosen
2002-06-18 14:56               ` Stephen Leake
2002-06-18 17:08                 ` Hyman Rosen
2002-06-16  3:15         ` Lyle McKennot
2002-06-16  3:51           ` Pat Rogers
  -- strict thread matches above, loose matches on Subject: below --
2002-06-14 14:31 ada paper critic Alderson, Paul A.
2002-06-14 15:16 ` Darren New
2002-06-14 15:58 ` Andrew Maizels
2002-06-14 17:00   ` chris.danx
2002-06-14 18:44     ` Jeffrey Carter
2002-06-14 20:26       ` Immanuel Scholz
2002-06-14 22:06         ` Ehud Lamm
2002-06-14 22:01           ` Immanuel Scholz
2002-06-14 22:38             ` sk
2002-06-15 11:28               ` Immanuel Scholz
2002-06-15 18:10                 ` sk
2002-06-15 14:30               ` Ted Dennison
2002-06-15 17:36                 ` sk
2002-06-16  3:08                 ` Gautier
2002-06-16  0:05               ` AG
2002-06-16 21:05                 ` Gautier
2002-06-14 23:10             ` tmoran
2002-06-15 14:19         ` Ted Dennison
2002-06-15 23:04           ` Darren New
2002-06-15 23:38             ` Darren New
2002-06-17 10:56           ` Immanuel Scholz
2002-06-17 19:56             ` Brian Rogoff
2002-06-17 20:47               ` Marin David Condic
2002-06-18 18:10                 ` Brian Rogoff
2002-06-18 18:51                   ` Robert A Duff
2002-06-18 19:08                     ` Hyman Rosen
2002-06-18 20:47                       ` Robert A Duff
2002-06-19  5:28                 ` Robert I. Eachus
2002-06-18 14:01               ` Robert A Duff
2002-06-14 20:58 ` Ted Dennison
2002-06-14 21:30   ` Immanuel Scholz
2002-06-15  1:24     ` Larry Kilgallen
2002-06-15  3:02 ` Vinzent Hoefler
2002-06-15 21:54 ` AG
2002-06-14 19:42 Gautier no_direct_reply_please
2002-06-15 15:08 ` Simon Wright
2002-06-15 22:52 ` Robert A Duff
2002-06-16  0:38   ` AG
2002-06-17 14:15     ` Marin David Condic
2002-06-18 13:52       ` Robert A Duff
2002-06-18 15:41         ` Darren New
2002-06-18 18:04         ` Jeffrey Carter
2002-06-19  1:04           ` Rod Haper
2002-06-16 22:19   ` Ted Dennison
2002-06-16 23:02     ` Robert A Duff
2002-06-17  7:07       ` Kevin Cline
2002-06-18 20:54         ` Robert A Duff
2002-06-18 22:15           ` Larry Kilgallen
2002-06-14 20:06 Gautier no_direct_reply_please
2002-06-14 20:48 ` Baugereau
2002-06-15 14:38   ` Ted Dennison
2002-06-14 20:36 Beard, Frank [Contractor]
2002-06-14 21:34 ` Immanuel Scholz
2002-06-15  4:14   ` Lyle McKennot
2002-06-14 22:08 Beard, Frank [Contractor]
2002-06-14 22:18 Beard, Frank [Contractor]
2002-06-15  1:38 ` Jeffrey Carter
2002-06-14 22:28 Gautier direct_replies_not_read
2002-06-15 14:43 ` Ted Dennison
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox