[omniORB] Thread-safety of Any with local calls

Chris Newbold cnewbold@laurelnetworks.com
Mon Sep 30 21:29:01 2002


On Mon, 2002-09-30 at 09:37, Duncan Grisby wrote:

> 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.

Mmmm. That sounded nice at first, but in my case the Any is burried
inside another structure. Though the code that's processing these
messages groks that structure, I'm not sure it helps: I end up having to
copy the entire structure to get a new Any, but there's no way to use
the void* constructor in that context...

Here's the IDL for the structure:

        // IDL
        
        struct Message {
        	string topic;
        	any contents;
        };
        
We can't do...

        // C++
        
        Messsage orig;
        Message safe(orig);
        	
...because that uses the wrong constructor and is not thread safe...

        // C++
        	
        Message orig;
        Message safe;
        safe.topic = orig.topic;
        safe.contents.replace(orig.contents.type(), 		   		     
        orig.contents.value());
        
...but now we're copying topic and paying for the default construction
of contents inside safe...
        
-- 
====( Chris Newbold  <cnewbold@laurelnetworks.com> )==========================
      Laurel Networks, Inc. voice: +1 412 809 4200 fax: +1 412 809 4201
"If you fool around with a thing for very long you will screw it up." --Murphy
------------------------------------------------------------------------------