Previous Up Next

Chapter 13  Current Objects

13.1  The Concept of Thread-local Data

The UNIX getpid() function returns an integer “process identifier” that uniquely identifies the process. Likewise, libraries of threading primitives provide a similar function, perhaps called get_thread_id(), that returns an integer to uniquely identify the current thread. The name of this function varies across different threading packages. A common coding technique used in multi-threaded programs is to use a lookup table to provide a mapping from a thread identifier to associated data. This technique allows a programmer to associate a different piece of data with different threads. The technique is often called thread-local data or thread-specific data.

13.2  Current Objects Provide Thread-local Data

CORBA uses the term Current to mean thread-local data.1 Actually, CORBA defines a few different types of current object. For example, there is one for security, another for transactions, and yet another for request dispatching. All of the current interfaces are defined in IDL, and they all inherit from an empty base type called CORBA::Current.


module CORBA { local interface Current { }; ... }; module PortableServer { ... typedef sequence<octet> ObjectId; local interface Current : CORBA::Current { exception NoContext { }; POA get_POA() raises(NoContext); ObjectId get_object_id() raises(NoContext); }; ... };
Figure 13.1: IDL definition of Current types

As an example, PortableServer::Current inherits from CORBA::Current and is used to access information about the target object for the request being dispatched by the current thread. The definitions of these types are shown in Figure 13.1.

Current objects are accessed by specifying the relevant name as a parameter to resolve_initial_references(), which is discussed in Section 3.4.1. For example, the PortableServer::Current singleton object is called POACurrent because you gain access to it by passing "POACurrent" as a parameter to resolve_initial_references(). Use of POACurrent is required when implementing servers with the “default servant” model (Section 5.6.4), and is optional with the other POA models.


1
To be pedantic, Current is data associated with a request rather than a thread. However, since a request is executed within the context of a thread, the concept of request-local data is usually synonymous with thread-local data, and thinking of current as being thread-local data is “accurate enough” for most discussions.

Previous Up Next