Re: Bad Multi-Threading Performance

2000-12-21 Thread Ned Seagoon


Here, as promised is my FreeMap (was AccumulatorMap). Reads don't require 
any syncronization and thus run nice and fast...

Comments people?

Regards
And a merry xmas if I don't speak to you before...

Ned
_
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.

 freemap.zip


Re: Bad Multi-Threading Performance

2000-12-21 Thread Ned Seagoon


Here, as promised is my FreeMap (was AccumulatorMap). Reads don't require 
any syncronization and thus run nice and fast...

Comments people?

Regards
And a merry xmas if I don't speak to you before...

Ned
_
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.

 freemap.zip


Re: Bad Multi-Threading Performance

2000-12-20 Thread Ned Seagoon

>From: Matthew Strayer <[EMAIL PROTECTED]>

>The situation you describe does not cause deadlock because the wait()
>call in thread
>2 releases the synchronized lock.

Ahh - didn't realise that! It's not been in any docs I've read before. Now, 
i've found it buried now in 4 lines of page 184 of Concurrent programming in 
Java.

>The only way I can think of to alleviate this problem is use different
>synchronization primitives.  Unfortunately, Java
>doesn't have them.  And all libraries that simulate these use
>synchronization!

heheheh - hooray for Java :-)

>Now, maybe someone here could hack some byte code
>(does Java have a set-and-test instruction??) and
>produce them... ;-)

Trouble is with a test and set is it atomic? I would imagine why the lack of 
better sync options and test & set options plus say a version of interlocked 
increment is perhaps due to the 'lowest common denominator' basis of java.

Regards
Ned

_
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.




Re: Bad Multi-Threading Performance

2000-12-20 Thread Matthew Strayer

 >Firstly, it looks to me like your code would hang in a deadlock. Take
 >for
 >example..
 >
 >Thread1Thread2
 >enter beginReading()
 >exit beginReading()
 >doing some reading enter beginWriting() [and blocking]
 >now can't call endReading()
 >
 >Now it looks like to me, that this is a deadlock. Thread2 is
 >syncronized on  the object and waiting for notification. Unfortunately 
Thread1 now
 >cannot enter endReading as Thread2 is holding the sync lock on the object.

The situation you describe does not cause deadlock because the wait() 
call in thread
2 releases the synchronized lock.  Basically, Java synchronization is 
built around
the idea of a "monitor" with wait() and notify() methods (reference your 
favorite
OS book).  Unfortunately, Java does
not allow the use of signaling multiple conditions on a wait (without 
some ugly hacks).
I suppose they designed Java this way because with monitors it is easier 
to prove code
correct than it is with semaphores or other primitives.

 >The second issue is that looks to me as if (in the case of the
 >ReadersPreferred) that if there are enough threads trying to read and
 >the
 >read takes a reasonable amount of time, then writers could block
 >indefinately.

This is correct.  Perhaps the class should be called 
WritersStarvationMonitor.  One could use
an alternating scheme (between batches of readers and a single writer) 
as you describe.


 >But what we do have now are two syncronized methods to get and release
 >access for a read - and as the read should be very fast, this may have
 >a
 >negative impact on the throughput of multi-threaded reads. Syncronized
 >calls
 >have a large performance impact - as does try/catch/finally which you
 >will
 >now have to put around your reading routines

The only way I can think of to alleviate this problem is use different
synchronization primitives.  Unfortunately, Java
doesn't have them.  And all libraries that simulate these use 
synchronization!
Now, maybe someone here could hack some byte code
(does Java have a set-and-test instruction??) and
produce them... ;-)

Regards,

Matt