Re: JavaMemoryModel: Code in the JDK that fails under current memory model

From: Joseph Bowbeer (jozart@csi.com)
Date: Sun Jul 18 1999 - 18:00:09 EDT


----- Original Message -----
From: Bill Pugh <pugh@cs.umd.edu>
To: <javaMemoryModel@cs.umd.edu>
Sent: Monday, July 12, 1999 11:40 AM

>
> Has anyone put together a list of places
> in the JDK that assume initialization safety?
>
> Here are some I've found:
>
> There are synchronized setFoo and matching unsynchronized getFoo
> methods, operating on references, in:
>
> java/awt/CheckboxGroup.set/get Current

+ java/awt/Checkbox.set/get CheckboxGroup:

    public void setCheckboxGroup(CheckboxGroup g) {
        CheckboxGroup group = this.group;
        if (group != null) {
            group.setSelectedCheckbox(null);
        }
        /* Locking check box above could cause deadlock with
         * CheckboxGroup's setSelectedCheckbox method.
         */
        synchronized (this) {
            this.group = g;
            /* ... */
        }
    }

Fortunately, none of your examples notify any listeners. To avoid deadlock,
the beans spec advises against holding a lock while listeners are being
notified. (For example, one thread may be trying to remove a listener while
another thread is trying to notify the listener.) This however *is* the case
with java/awt/Component's half-sync'd set/get Font methods. Yikes.

--
Joe Bowbeer

------------------------------- This is the JavaMemoryModel mailing list, managed by Majordomo 1.94.4.

To send a message to the list, email JavaMemoryModel@cs.umd.edu To send a request to the list, email majordomo@cs.umd.edu and put your request in the body of the message (use the request "help" for help). For more information, visit http://www.cs.umd.edu/~pugh/java/memoryModel



This archive was generated by hypermail 2b29 : Thu Oct 13 2005 - 07:00:17 EDT