Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      operator==,!=,<,<=,>,>=,<=>(std::thread::id)

      From cppreference.com
      <cpp‎ |thread‎ |thread‎ |id
       
       
      Concurrency support library
      Threads
      (C++11)
      (C++20)
      this_thread namespace
      (C++11)
      (C++11)
      (C++11)
      Cooperative cancellation
      Mutual exclusion
      Generic lock management
      (C++11)
      (C++11)
      (C++11)
      (C++11)
      Condition variables
      (C++11)
      Semaphores
      Latches and Barriers
      (C++20)
      (C++20)
      Futures
      (C++11)
      (C++11)
      (C++11)
      Safe reclamation
      Hazard pointers
      Atomic types
      (C++11)
      (C++20)
      Initialization of atomic types
      (C++11)(deprecated in C++20)
      (C++11)(deprecated in C++20)
      Memory ordering
      (C++11)(deprecated in C++26)
      Free functions for atomic operations
      Free functions for atomic flags
       
       
      std::thread::id
      Member functions
      Non-member functions
      operator==operator!=operator<operator<=operator>operator>=operator<=>
      (until C++20)(until C++20)(until C++20)(until C++20)(until C++20)(C++20)
      Helper classes
       
      Defined in header<thread>
      bool operator==(std::thread::id lhs,std::thread::id rhs)noexcept;
      (1)(since C++11)
      bool operator!=(std::thread::id lhs,std::thread::id rhs)noexcept;
      (2)(since C++11)
      (until C++20)
      bool operator<(std::thread::id lhs,std::thread::id rhs)noexcept;
      (3)(since C++11)
      (until C++20)
      bool operator<=(std::thread::id lhs,std::thread::id rhs)noexcept;
      (4)(since C++11)
      (until C++20)
      bool operator>(std::thread::id lhs,std::thread::id rhs)noexcept;
      (5)(since C++11)
      (until C++20)
      bool operator>=(std::thread::id lhs,std::thread::id rhs)noexcept;
      (6)(since C++11)
      (until C++20)
      std::strong_ordering operator<=>(std::thread::id lhs,
                                       std::thread::id rhs)noexcept;
      (7)(since C++20)

      Compares two thread identifiers.

      1,2) Checks whetherlhs andrhs represent either the same thread, or no thread.
      3-7) Compareslhs andrhs in an unspecified total ordering.

      The<,<=,>,>=, and!= operators aresynthesized fromoperator<=> andoperator== respectively.

      (since C++20)

      Contents

      [edit]Parameters

      lhs, rhs - thread identifiers to compare

      [edit]Return value

      1-6)true if the corresponding relation holds,false otherwise.
      7)std::strong_ordering::less iflhs is less thanrhs in the total ordering; otherwisestd::strong_ordering::greater ifrhs is less thanlhs in the total ordering; otherwisestd::strong_ordering::equal.

      [edit]Complexity

      Constant.

      [edit]Example

      Run this code
      #include <cassert>#include <chrono>#include <iostream>#include <thread>  int main(){auto work=[]{std::this_thread::sleep_for(std::chrono::seconds(1));};std::thread t1(work);std::thread t2(work); assert(t1.get_id()== t1.get_id() and           t2.get_id()== t2.get_id() and           t1.get_id()!= t2.get_id()); if(constauto cmp= t1.get_id()<=> t2.get_id(); cmp<0)std::cout<<"id1 < id2\n";elsestd::cout<<"id1 > id2\n"; std::cout<<"id1: "<< t1.get_id()<<"\n""id2: "<< t2.get_id()<<'\n';     t1.join();    t2.join();}

      Possible output:

      id1 > id2id1: 139741717640896id2: 139741709248192

      [edit]See also

      C documentation forthrd_equal
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/thread/thread/id/operator_cmp&oldid=160780"

      [8]ページ先頭

      ©2009-2025 Movatter.jp