oj mrJudge
Toggle navigation
  • Login
    • Forget Password
      Login
User Image

Hello, Stranger

Guest
  • Analysis Mode
  • Problems
    • All Problems
    • Latest Problems
  • Join Us Now
  • Registration
  • Contact Us
  • Infomation
  • C++ Reference
  • About
    • Help
    • Terms of Use
    • Technical Specifications
    • Credits

C++ Reference as of 28 May 2018

Standard library header <mutex> - cppreference.com

Standard library header <mutex>

From cppreference.com
< cpp‎ | header
 
C++
Language
Headers
Library concepts
Language support library
Diagnostics library
Utilities library
Strings library
Containers library
Algorithms library
Iterators library
Numerics library
Input/output library
Localizations library
Regular expressions library (C++11)
Atomic operations library (C++11)
Thread support library (C++11)
Filesystem library (C++17)
Technical Specifications
 
Standard Library header files
Language Support
<cstddef>
<limits>
<climits>
<version>
<cfloat>
<cstdint>
<new>

<typeinfo>
<exception>
<initializer_list>

<csignal>
<csetjmp>
<cstdarg>

Diagnostics
<stdexcept>
<cassert>
<cerrno>
<system_error>
General utilities
<utility>
<memory>
<memory_resource>
<scoped_allocator>    
<compare>
<bitset>
<tuple>
<optional>
<any>
<variant>
<type_traits>
<ratio>
<chrono>
<typeindex>
<functional>
<ctime>
<cstdlib>



Strings
<string>
<string_view>
<cctype>
<cwctype>
<cwchar>
<cuchar>
<cstring>
<charconv>
Localization
<locale>
<codecvt>
<clocale>
Containers
<span>
<array>
<vector>
<deque>
<forward_list>
<list>
<map>
<set>
<queue>
<unordered_map>
<unordered_set>
<stack>
Iterators
<iterator>
Algorithms
<algorithm>
<execution>
Numerics
<complex>
<random>
<valarray>
<numeric>
<cfenv>
<cmath>
Input/Output
<iosfwd>
<ios>
<iomanip>
<streambuf>
<istream>
<ostream>
<iostream>

<sstream>
<fstream>
<syncstream>

<cstdio>
<cinttypes>
<strstream>

Regular expressions
<regex>
Filesystem support
<filesystem>
Thread support
<thread>
<atomic>
<mutex>
<shared_mutex>
<condition_variable>
<future>
C compatibility
<ciso646>
<cstdalign>
<cstdbool>
<ccomplex>
<ctgmath>

 

This header is part of the thread support library.

Classes

mutex
(C++11)
provides basic mutual exclusion facility
(class)
timed_mutex
(C++11)
provides mutual exclusion facility which implements locking with a timeout
(class)
recursive_mutex
(C++11)
provides mutual exclusion facility which can be locked recursively by the same thread
(class)
recursive_timed_mutex
(C++11)
provides mutual exclusion facility which can be locked recursively
by the same thread and implements locking with a timeout
(class)
lock_guard
(C++11)
implements a strictly scope-based mutex ownership wrapper
(class template)
unique_lock
(C++11)
implements movable mutex ownership wrapper
(class template)
defer_lock_ttry_to_lock_tadopt_lock_t
(C++11)(C++11)(C++11)
tag type used to specify locking strategy
(class)
defer_locktry_to_lockadopt_lock
(C++11)(C++11)(C++11)
tag constants used to specify locking strategy
(constant)
once_flag
(C++11)
helper object to ensure that call_once invokes the function only once
(class)

Functions

try_lock
(C++11)
attempts to obtain ownership of mutexes via repeated calls to try_lock
(function template)
lock
(C++11)
locks specified mutexes, blocks if any are unavailable
(function template)
call_once
(C++11)
invokes a function only once even if called from multiple threads
(function template)
std::swap(std::unique_lock)
(C++11)
specialization of std::swap for unique_lock
(function template)

Synopsis

namespace std {
    class mutex;
    class recursive_mutex;
    class timed_mutex;
    class recursive_timed_mutex;
 
    struct defer_lock_t { explicit defer_lock_t() = default; };
    inline constexpr defer_lock_t defer_lock { };
 
    struct try_to_lock_t { explicit try_to_lock_t() = default; };
    inline constexpr try_to_lock_t try_to_lock { };
 
    struct adopt_lock_t { explicit adopt_lock_t() = default; };
    inline constexpr adopt_lock_t adopt_lock { };
 
    template <class Mutex> class lock_guard;
    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);
}

Class std::mutex

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

Class std::recursive_mutex

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();
    typedef /*implementation-defined*/ native_handle_type;
    native_handle_type native_handle();
};

Class std::timed_mutex

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();
    typedef /*implementation-defined*/ native_handle_type;
    native_handle_type native_handle();
};

Class std::recursive_timed_mutex

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();
    typedef /*implementation-defined*/ native_handle_type;
    native_handle_type native_handle();
};

Class std::lock_guard

template <class Mutex>
class lock_guard {
 public:
    typedef Mutex mutex_type;
    explicit lock_guard(mutex_type& m);
    lock_guard(mutex_type& m, adopt_lock_t);
    ~lock_guard();
    lock_guard(lock_guard const&) = delete;
    lock_guard& operator=(lock_guard const&) = delete;
 private:
    mutex_type& pm; // exposition only
};

Class std::unique_lock

template <class Mutex>
class unique_lock {
 public:
    typedef Mutex mutex_type;
 
    // construct/copy/destroy:
    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(unique_lock const&) = delete;
    unique_lock& operator=(unique_lock const&) = delete;
    unique_lock(unique_lock&& u) noexcept;
    unique_lock& operator=(unique_lock&& u) noexcept;
 
    // locking:
    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();
 
    // modifiers:
    void swap(unique_lock& u) noexcept;
    mutex_type *release() noexcept;
 
    // observers:
    bool owns_lock() const noexcept;
    explicit operator bool () const noexcept;
    mutex_type* mutex() const noexcept;
 
 private:
    mutex_type *pm; // exposition only
    bool owns; // exposition only
};

Class std::once_flag

struct once_flag {
    constexpr once_flag() noexcept;
    once_flag(const once_flag&) = delete;
    once_flag& operator=(const once_flag&) = delete;
};
Retrieved from "http://en.cppreference.com/mwiki/index.php?title=cpp/header/mutex&oldid=95191"
Navigation
  • Online version
  • Offline version retrieved 2018-04-14 22:05.
  • This page was last modified on 26 August 2017, at 08:40.
  • This page has been accessed 45,335 times.
mrJudge 31.05.2018 (F43DD)
Copyright © 2018 mrJudge. All rights reserved.

Under Construction

Stats Tab Content

Under Construction too