# Class CountingThreadLocalManager
Internal policy used to manage thread specific storage for a limited number of threads.

Defined in | <seqan/parallel.h>
Signature | `struct SimpleThreadLocalManager;`

## Member Function Overview

- `auto local(map, init);`
  Implements the specific `local` policy.

## Detailed Description

Uses a shared mutex to synchronize concurrent access to the storage buffer (multiple read, single write). This policy checks if the thread-id was already registered and if not creates a new storage instance for the given thread-id. In addition maintains an atomic counter to only check for existing values as long as the counter is not 0. This can be used if the number of threads registering at the EnumerableThreadLocal instance, is known beforehand. In this case, as soon as all threads have been registered and obtained their local storage, no further synchronization is necessary.

## See Also

- SimpleThreadLocalManager

## Member Functions Detail

### `auto local(map, init);`

Implements the specific `local` policy.

#### Parameters

`map` | The buffer provided by the EnumerableThreadLocal instance to the hold the thread local storage. Must satisfy the `std::map` interface.
`init` | The value used to initialize created storage.

#### Returns

`auto` | A tuple containing a lvalue reference to the associated storage and a boolean indicating first time access of the given thread-id.

#### Data Races

thread-safe.

#### Dox Sources

    /*!
     * @class CountingThreadLocalManager
     *
     * @headerfile <seqan/parallel.h>
     *
     * @brief Internal policy used to manage thread specific storage for a limited
     *        number of threads.
     *
     * @signature struct SimpleThreadLocalManager;
     *
     * Uses a shared mutex to synchronize concurrent access to the storage buffer
     * (multiple read, single write). This policy checks if the thread-id was
     * already registered and if not creates a new storage instance for the given
     * thread-id. In addition maintains an atomic counter to only check for existing
     * values as long as the counter is not 0. This can be used if the number of
     * threads registering at the @link EnumerableThreadLocal @endlink instance, is
     * known beforehand. In this case, as soon as all threads have been registered
     * and obtained their local storage, no further synchronization is necessary.
     *
     * @see SimpleThreadLocalManager
     *
     * @fn CountingThreadLocalManager::local
     *
     * @headerfile <seqan/parallel.h>
     *
     * @brief Implements the specific <tt>local</tt> policy.
     *
     * @signature auto local(map, init);
     *
     * @param map The buffer provided by the @link EnumerableThreadLocal @endlink
     *            instance to the hold the thread local storage. Must satisfy the
     *            <tt>std::map</tt> interface.
     * @param init The value used to initialize created storage.
     *
     * @return auto A tuple containing a lvalue reference to the associated storage
     *              and a boolean indicating first time access of the given thread-
     *              id.
     *
     * @datarace thread-safe.
     */