[concurrency-interest] New bug pattern, way to common

Bob Lee crazybob at crazybob.org
Fri Mar 14 16:08:02 EDT 2008


Nice one.

On Fri, Mar 14, 2008 at 12:28 PM, Bill Pugh <pugh at cs.umd.edu> wrote:

> I identified a new concurrency bug pattern that is way too common:
>
> Synchronizing on a field in order to prevent concurrent access to that
> field.
>
> For example:
>   /**
>      * Add a lifecycle event listener to this component.
>      *
>      * @param listener The listener to add
>      */
>     public void addInstanceListener(InstanceListener listener) {
>
>       synchronized (listeners) {
>           InstanceListener results[] =
>             new InstanceListener[listeners.length + 1];
>           for (int i = 0; i < listeners.length; i++)
>               results[i] = listeners[i];
>           results[listeners.length] = listener;
>           listeners = results;
>       }
>
>     }
>
> There are 26 occurrences of this pattern in apache-tomcat.
>
> Of course, if the field in question is of type Boolean, it becomes
> exceptionally problematical.
>
> Bill
> _______________________________________________
> Concurrency-interest mailing list
> Concurrency-interest at altair.cs.oswego.edu
> http://altair.cs.oswego.edu/mailman/listinfo/concurrency-interest
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: /pipermail/attachments/20080314/f2b18db1/attachment.html 


More information about the Concurrency-interest mailing list