Menu

#94 Synchronization error

bug
open
nobody
jdbc (31)
5
2001-07-19
2001-07-19
Anonymous
No

The methods 'jdbcConnection::openStandalone()'
and 'jdbcConnection::closeStandalone()' could set
wrong values for 'usageCount' of a database because
synchronization is made over 'jdbcConnection' objects,
so several calls to 'openStandalone'
and 'closeStandalone' can be executed concurrently.
This means that different threads could read the same
value for 'iUsageCount' and update it with a wrong
value. Example:

Suppose that initial value for "myDatabaseName"
iUsageCount is 1.

Thread 1 executes over jdbcConnection#1
Thread 2 executes over jdbcConnection#2

Thread 1:

usage=1+((Integer)iUsageCount.get
("myDatabaseName")).intValue();

// Now thread 1 loses the processor

Thread 2:

usage=1+((Integer)iUsageCount.get
("myDatabaseName")).intValue();
// The value of usage is the same than got by thread 1

iUsageCount.put("myDatabaseName",new Integer(usage));

// Now thread 2 loses the processor

Thread 1:

iUsageCount.put("myDatabaseName",new Integer(usage));

// At this point, usage counter for "myDatabase" is 2
when the right value should be 3

After the 'jdbcConnection' objects have been used,
the 'closeStandalone' can make the value of usage
counter to be 0, so the Database object will be
removed and nxt accesses will fail.

Thanks.

Discussion


Log in to post a comment.

MongoDB Logo MongoDB