JvSynchronize nitpick

Paul Fisher pnfisher@redhat.com
Mon Mar 27 21:54:00 GMT 2000


Tom Tromey <tromey@cygnus.com> writes:

> That might be too magical, not to mention slow.

I'm rather fond of that magic.  How about something a bit simpler?

class JvSynchronizeHelper
{
  JvSynchronize sync;
public:
  bool done;
  JvSynchronizeHelper (const jobject &obj) : sync (obj), done (false) { }
};

#define synchronized(OBJECT) \
  for (JvSynchronizeHelper JvX (OBJECT); !JvX.done; JvX.done = true)

Of course, this could wreak havoc if a `break' or a `continue' were to
occur inside of a synchronized block contained within an iterative
construct.  For that situation, one could always fall back to using
JvSynchronize, but would that be too confusing?


More information about the Java mailing list