Message6805

Author ajdavis
Recipients ajdavis
Date 2012-03-16.20:16:52
SpamBayes Score 3.517926e-07
Marked as misclassified No
Message-id <1331929013.04.0.00349845243949.issue1854@psf.upfronthosting.co.za>
In-reply-to
Content
Docs say:

Jython implements dict and set by using Java’s ConcurrentHashMap. This means you can just use these standard Python types, and still get high performance concurrency. (They are also atomic like in CPython, as we will describe.)

However, I'm looking at the source code in 2.5.2 in PySet.java and BaseSet.java, and it doesn't use ConcurrentHashMap. Perhaps it ought to. In fact there's a race condition in pop(), where many threads can all pop the same object from the set. Set uses an iterator to get the first object, then removes the object. In between those two operations is a critical section not protected by a lock.

While testing PyMongo 2.2 (which I'm developing -- it'll be released shortly) I saw this race condition causing bugs in tests with about 40 threads all popping from the set concurrently. Many of them got the same object.
History
Date User Action Args
2012-03-16 20:16:53ajdavissetmessageid: <1331929013.04.0.00349845243949.issue1854@psf.upfronthosting.co.za>
2012-03-16 20:16:53ajdavissetrecipients: + ajdavis
2012-03-16 20:16:53ajdavislinkissue1854 messages
2012-03-16 20:16:52ajdaviscreate