On Sat, Apr 18, 2009 at 4:28 AM,  <nextgens at freenetproject.org> wrote:
> Author: nextgens
> Date: 2009-04-17 20:28:59 +0000 (Fri, 17 Apr 2009)
> New Revision: 26956
>
> Modified:
> ? branches/nextgens-stuffs/freenet/src/freenet/io/comm/MessageCore.java
> Log:
> Use the locking idiom properly (hopefully)
>
> Modified: 
> branches/nextgens-stuffs/freenet/src/freenet/io/comm/MessageCore.java
> ===================================================================
> --- branches/nextgens-stuffs/freenet/src/freenet/io/comm/MessageCore.java ? ? 
> ? 2009-04-17 20:13:11 UTC (rev 26955)
> +++ branches/nextgens-stuffs/freenet/src/freenet/io/comm/MessageCore.java ? ? 
> ? 2009-04-17 20:28:59 UTC (rev 26956)
[...]
> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?try {
> + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 
> messageFiltersReadLock.unlock();

@1 err.. unlock and relock would cause problem. see @2

> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 
> ?messageFiltersWriteLock.lock();
> - ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? i.remove();
> + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? if (f.match(m, 
> tStart)) {
[...]
> + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? i.remove();

@2: what if another thread is at @1, and you removed his filter?


3 options:
  1] take a snapshot of the the message filter

  2] use java.util.concurrent.CopyOnWriteArrayList<E>

  3] use  org.jboss.cache.lock.ReadWriteLockWithUpgrade   (it is slow,
but it allow upgrade from read lock to write lock)

Reply via email to