Namespaces
Variants

Standard library header <mutex> (C++11)

From cppreference.net
Standard library headers

이 헤더는 스레드 지원 라이브러리의 일부입니다.

목차

클래스

(C++11)
기본 상호 배제 기능을 제공함
(클래스)
타임아웃 기능이 있는 잠금을 구현하는 상호 배제 기능을 제공합니다
(클래스)
동일 스레드에서 재귀적으로 잠글 수 있는 상호 배제 기능을 제공함
(클래스)
동일 스레드에 의해 재귀적으로 잠글 수 있고 타임아웃 기능을 구현하는
상호 배제 기능을 제공함
(클래스)
(C++11)
엄격한 범위 기반 뮤텍스 소유권 래퍼를 구현합니다
(클래스 템플릿)
이동 가능한 뮤텍스 소유권 래퍼를 구현함
(클래스 템플릿)
데드락 방지 다중 뮤텍스 RAII 래퍼
(클래스 템플릿)
(C++11)
call_once 가 함수를 단 한 번만 호출하도록 보장하는 헬퍼 객체
(클래스)

함수

(C++11)
try_lock 호출을 반복하여 뮤텍스의 소유권을 획득하려 시도합니다
(함수 템플릿)
(C++11)
지정된 뮤텍스들을 잠금, 사용 불가능한 경우 블록
(함수 템플릿)
(C++11)
여러 스레드에서 호출되더라도 함수를 한 번만 호출합니다
(함수 템플릿)
std::swap 알고리즘을 특수화합니다
(함수 템플릿)

태그

잠금 전략을 지정하는 데 사용되는 태그
(태그)

시놉시스

namespace std {
  class mutex;
  class recursive_mutex;
  class timed_mutex;
  class recursive_timed_mutex;
  struct defer_lock_t { explicit defer_lock_t() = default; };
  struct try_to_lock_t { explicit try_to_lock_t() = default; };
  struct adopt_lock_t { explicit adopt_lock_t() = default; };
  inline constexpr defer_lock_t  defer_lock { };
  inline constexpr try_to_lock_t try_to_lock { };
  inline constexpr adopt_lock_t  adopt_lock { };
  template<class Mutex> class lock_guard;
  template<class... MutexTypes> class scoped_lock;
  template<class Mutex> class unique_lock;
  template<class Mutex>
    void swap(unique_lock<Mutex>& x, unique_lock<Mutex>& y) noexcept;
  template<class L1, class L2, class... L3> int try_lock(L1&, L2&, L3&...);
  template<class L1, class L2, class... L3> void lock(L1&, L2&, L3&...);
  struct once_flag;
  template<class Callable, class... Args>
    void call_once(once_flag& flag, Callable&& func, Args&&... args);
}

클래스 std::mutex

namespace std {
  class mutex {
  public:
    constexpr mutex() noexcept;
    ~mutex();
    mutex(const mutex&) = delete;
    mutex& operator=(const mutex&) = delete;
    void lock();
    bool try_lock();
    void unlock();
    using native_handle_type = /* implementation-defined */;
    native_handle_type native_handle();
  };
}

클래스 std::recursive_mutex

namespace std {
  class recursive_mutex {
  public:
    recursive_mutex();
    ~recursive_mutex();
    recursive_mutex(const recursive_mutex&) = delete;
    recursive_mutex& operator=(const recursive_mutex&) = delete;
    void lock();
    bool try_lock() noexcept;
    void unlock();
    using native_handle_type = /* implementation-defined */;
    native_handle_type native_handle();
  };
}

클래스 std::timed_mutex

namespace std {
  class timed_mutex {
  public:
    timed_mutex();
    ~timed_mutex();
    timed_mutex(const timed_mutex&) = delete;
    timed_mutex& operator=(const timed_mutex&) = delete;
    void lock();    // 블로킹 방식
    bool try_lock();
    template<class Rep, class Period>
      bool try_lock_for(const chrono::duration<Rep, Period>& rel_time);
    template<class Clock, class Duration>
      bool try_lock_until(const chrono::time_point<Clock, Duration>& abs_time);
    void unlock();
    using native_handle_type = /* 구현 정의 */;
    native_handle_type native_handle();
  };
}

클래스 std::recursive_timed_mutex

namespace std {
  class recursive_timed_mutex {
  public:
    recursive_timed_mutex();
    ~recursive_timed_mutex();
    recursive_timed_mutex(const recursive_timed_mutex&) = delete;
    recursive_timed_mutex& operator=(const recursive_timed_mutex&) = delete;
    void lock();    // 블로킹
    bool try_lock() noexcept;
    template<class Rep, class Period>
      bool try_lock_for(const chrono::duration<Rep, Period>& rel_time);
    template<class Clock, class Duration>
      bool try_lock_until(const chrono::time_point<Clock, Duration>& abs_time);
    void unlock();
    using native_handle_type = /* 구현 정의 */;
    native_handle_type native_handle();
  };
}

클래스 템플릿 std::lock_guard

namespace std {
  template<class Mutex>
  class lock_guard {
  public:
    using mutex_type = Mutex;
    explicit lock_guard(mutex_type& m);
    lock_guard(mutex_type& m, adopt_lock_t);
    ~lock_guard();
    lock_guard(const lock_guard&) = delete;
    lock_guard& operator=(const lock_guard&) = delete;
  private:
    mutex_type& pm;             // 설명 전용
  };
}

클래스 템플릿 std:: scoped_lock

namespace std {
  template<class... MutexTypes>
  class scoped_lock {
  public:
    using mutex_type = Mutex;   // MutexTypes...가 단일 타입 Mutex로 구성된 경우
    explicit scoped_lock(MutexTypes&... m);
    explicit scoped_lock(adopt_lock_t, MutexTypes&... m);
    ~scoped_lock();
    scoped_lock(const scoped_lock&) = delete;
    scoped_lock& operator=(const scoped_lock&) = delete;
  private:
    tuple<MutexTypes&...> pm;   // 설명 전용
  };
}

클래스 템플릿 std::unique_lock

namespace std {
  template<class Mutex>
  class unique_lock {
  public:
    using mutex_type = Mutex;
    // 생성/복사/소멸
    unique_lock() noexcept;
    explicit unique_lock(mutex_type& m);
    unique_lock(mutex_type& m, defer_lock_t) noexcept;
    unique_lock(mutex_type& m, try_to_lock_t);
    unique_lock(mutex_type& m, adopt_lock_t);
    template<class Clock, class Duration>
      unique_lock(mutex_type& m, const chrono::time_point<Clock, Duration>& abs_time);
    template<class Rep, class Period>
      unique_lock(mutex_type& m, const chrono::duration<Rep, Period>& rel_time);
    ~unique_lock();
    unique_lock(const unique_lock&) = delete;
    unique_lock& operator=(const unique_lock&) = delete;
    unique_lock(unique_lock&& u) noexcept;
    unique_lock& operator=(unique_lock&& u);
    // 잠금
    void lock();
    bool try_lock();
    template<class Rep, class Period>
      bool try_lock_for(const chrono::duration<Rep, Period>& rel_time);
    template<class Clock, class Duration>
      bool try_lock_until(const chrono::time_point<Clock, Duration>& abs_time);
    void unlock();
    // 수정자
    void swap(unique_lock& u) noexcept;
    mutex_type* release() noexcept;
    // 관찰자
    bool owns_lock() const noexcept;
    explicit operator bool () const noexcept;
    mutex_type* mutex() const noexcept;
  private:
    mutex_type* pm;             // 설명 전용
    bool owns;                  // 설명 전용
  };
  template<class Mutex>
    void swap(unique_lock<Mutex>& x, unique_lock<Mutex>& y) noexcept;
}

클래스 std::once_flag

namespace std {
  struct once_flag {
    constexpr once_flag() noexcept;
    once_flag(const once_flag&) = delete;
    once_flag& operator=(const once_flag&) = delete;
  };
}