#7 Stress tests using a counting listener hang.

v0.5-b2
open
nobody
stress (1)
5
2004-10-06
2004-10-06
No

The class org.exolab.jmscts.core.CountingListener
provides access and update operations for the volatile
int _count. _count can be concurrently updated and
accessed by several consumers (like it is the case with
the test SendReceive50Size0KTest). However, in such a
case there isn’t any guarantee of whether _count is
atomically updated. A volatile variable state is copied
from global memory to local thread memory and when
modified it is stored back in main memory. But nothing
prevents two threads to read the same value from the
main memory and then concurrently locally update it!
For example this scenario is very likely to happen on a
multi processors box:
_count value is 10
Thread1 reads _count from main memory
Thread2 reads _count from main memory
Thread1 increments _count its local value is now 11.
Thread2 increments _count its local value is now 11.
Thread1 stores _count in main memory
Thread2 stores _count in main memory
_count value is 11 (and not 12 as expected).
The test hangs waiting for a message that has not been
counted.

I would like to suggest the following simple workaround:
Add a synchronization statement to the methods
onMessage(Message message) and getReceived() of the
class org.exolab.jmscts.core.CountingListener.

I hope this helps

Cheers

Arnaud

Discussion


Log in to post a comment.