1.cc 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // { dg-do run }
  2. // { dg-additional-options "-pthread" { target pthread } }
  3. // { dg-require-effective-target c++11 }
  4. // { dg-require-gthreads "" }
  5. // Copyright (C) 2010-2022 Free Software Foundation, Inc.
  6. //
  7. // This file is part of the GNU ISO C++ Library. This library is free
  8. // software; you can redistribute it and/or modify it under the
  9. // terms of the GNU General Public License as published by the
  10. // Free Software Foundation; either version 3, or (at your option)
  11. // any later version.
  12. // This library is distributed in the hope that it will be useful,
  13. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. // GNU General Public License for more details.
  16. // You should have received a copy of the GNU General Public License along
  17. // with this library; see the file COPYING3. If not see
  18. // <http://www.gnu.org/licenses/>.
  19. #include <mutex>
  20. #include <system_error>
  21. #include <testsuite_hooks.h>
  22. int main()
  23. {
  24. typedef std::mutex mutex_type;
  25. typedef std::unique_lock<mutex_type> lock_type;
  26. try
  27. {
  28. mutex_type m1, m2, m3;
  29. lock_type l1(m1, std::defer_lock),
  30. l2(m2, std::defer_lock),
  31. l3(m3, std::defer_lock);
  32. try
  33. {
  34. std::lock(l1, l2, l3);
  35. VERIFY( l1.owns_lock() );
  36. VERIFY( l2.owns_lock() );
  37. VERIFY( l3.owns_lock() );
  38. }
  39. catch (const std::system_error& e)
  40. {
  41. VERIFY( false );
  42. }
  43. }
  44. catch (const std::system_error& e)
  45. {
  46. VERIFY( false );
  47. }
  48. catch (...)
  49. {
  50. VERIFY( false );
  51. }
  52. return 0;
  53. }