---
name: "ACE_TSS"
section: "3"
platform: "linux"
package: "libace-doc"
version: "5.0.7-4"
release: "Debian 2.2 (Potato)"
platforms: ["linux"]
url: "https://new.carta.tech/ACE_TSS"
---

# ACE\_TSS(3)

Allows objects that are "physically" in thread specific storage (i.e., private to a thread) to be accessed as though they were "logically" global to a program.

## NAME

ACE\_TSS -  Allows objects that are "physically" in thread specific storage (i.e., private to a thread) to be accessed as though they were "logically" global to a program.

## SYNOPSIS

```
#include <ace/Synch_T.h>
template<class TYPE>
class ACE_TSS
{
  public:
    ACE_TSS (TYPE *ts_obj = 0);
    virtual ~ACE_TSS (void);
    TYPE *ts_object (void) const;
    TYPE *ts_object (TYPE *);
    TYPE *operator-> () const;
    operator TYPE *(void) const;
    virtual TYPE *make_TSS_TYPE (void) const;
    void dump (void) const;
  protected:
    TYPE *ts_get (void) const;
    int ts_init (void) const;
    TYPE *type_;
    ACE_Thread_Mutex keylock_;
    int once_;
    ACE_thread_key_t key_;
    static void cleanup (void *ptr);
    inline ACE_UNIMPLEMENTED_FUNC (
        void operator= (const ACE_TSS<TYPE> &)
        );
};
```

## DESCRIPTION

This class is a wrapper around the OS thread library thread-specific functions.  It uses the C++ operator-\> to shield applications from the details of accessing thread-specific storage.

NOTE:  TYPE cannot be a built-in type, but instead must be a user-defined class.  (Some compilers will allow a built-in type, but shouldn't.  Sun C++ won't, properly detecting the improper return type from operator-\>.)  See template class ACE\_TSS\_Type\_Adapter, below, for adapting built-in types to work with ACE\_TSS.

## Initialization and termination methods.

```
ACE_TSS (TYPE *ts_obj = 0);
```

If caller has passed us a non-NULL ts\_obj \*, then we'll just use this to initialize the thread-specific value (but only for the calling thread).  Thus, subsequent calls to operator-\> in this thread will return this value.  This is useful since it enables us to assign objects to thread-specific data that have arbitrarily complex constructors.

```
virtual ~ACE_TSS (void);
```

Deregister with thread-key administration.

## Accessors.

```
TYPE *ts_object (void) const;
```

Get the thread-specific object for the key associated with this object.  Returns 0 if the data has never been initialized, otherwise returns a pointer to the data.

```
TYPE *ts_object (TYPE *);
```

Set the thread-specific object for the key associated with this object.

```
TYPE *operator-> () const;
```

Use a "smart pointer" to get the thread-specific object associated with the key\_.

```
operator TYPE *(void) const;
```

Return or create and return the calling threads TYPE object.

```
virtual TYPE *make_TSS_TYPE (void) const;
```

Hook for construction parameters.

## Utility methods.

```
void dump (void) const;
```

Dump the state of an object.

ACE\_ALLOC\_HOOK\_DECLARE; Declare the dynamic allocation hooks.

## Disallow copying...

```
inline ACE_UNIMPLEMENTED_FUNC (
    void operator= (const ACE_TSS<TYPE> &)
    );
```

## AUTHOR

Doug Schmidt

## LIBRARY

ace
