[omniORB] Thread-safety of Any with local calls

Duncan Grisby duncan@grisby.org
Mon Sep 30 14:38:01 2002


On Monday 23 September, Chris Newbold wrote:

[...]
> Now, the first thing that each observer does is attempt to extract the
> contents of the message from the Any. As it turns out, extraction from
> an Any is _not_ thread safe, so the two observers wind up corrupting the
> buffered message and one or both get CORBA::MARSHAL.

[...]
> Is this a bug or a feature? :-)

Both ;-)

Access to Anys in omniORB is not thread safe, since the locking
overhead would be too large. In omniORB 2 and 3, marshalling Anys is
not thread safe either. In omniORB 4, marshalling is thread safe, but
other access still isn't. The CORBA spec doesn't say anything about
thread safety, so this is all CORBA compliant, although certainly
undesirable in your case.

All is not lost, however. If you use the omniORB specific Any
constructor that takes a void* argument, you can copy an Any without
copying its underlying buffer. Use code like

  CORBA::Any* a = // something in concurrent use
  CORBA::Any safe(a->type(), a->value())

Now, safe is an Any with its own state for access and marshalling, but
sharing the underlying buffer of the original Any.

Cheers,

Duncan.

-- 
 -- Duncan Grisby         --
  -- duncan@grisby.org     --
   -- http://www.grisby.org --