Re: unable to synchronize on primitive wrapper class?
Eric Sosman wrote:
The "could" should stand, though, since delaying is no
substitute for proper synchronization (e.g., calling join() on
both threads). Still, the race on the counts is probably not
the cause of the behavior the O.P. reports.
Indeed, and as that major issue had already been ably analyzed by you, I was
left to sweep up the crumbs of much lesser importance. Still, for
completeness's sake, I piped up with the incidental matter, resting assured
that the OP's major concern having been alleviated, they would have the
freedom to attend to second-tier matters that might (as you say, might) crop up.
Timing might not be enough for changes to percolate through. Absent explicit
inter-thread coordination, values could (emph. "could") disappear altogether
without ever propagating to other threads. This is far less likely on a
uni-processor machine than on a multi-CPU or multi-core unit, of course.
So rather than risking unlikely but strictly possible bugs, one might thing of
declaring a monitor that covers both "count" and "total". It's really just an
extension of the solution to the multiple Integer monitors - combine all
synchronization into a single gateway.
--
Lew