A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://en.cppreference.com/w/cpp/language/../memory/shared_ptr/atomic.html below:

std::atomic_...<std::shared_ptr> - cppreference.com

template< class T >
bool atomic_is_lock_free( const std::shared_ptr<T>* p );
(1) (since C++11)
(deprecated in C++20)
(removed in C++26) (2) (since C++11)
(deprecated in C++20)
(removed in C++26) (3) (since C++11)
(deprecated in C++20)
(removed in C++26) (4) (since C++11)
(deprecated in C++20)
(removed in C++26) (5) (since C++11)
(deprecated in C++20)
(removed in C++26) (6) (since C++11)
(deprecated in C++20)
(removed in C++26) (7) (since C++11)
(deprecated in C++20)
(removed in C++26) (8) (since C++11)
(deprecated in C++20)
(removed in C++26) (9) (since C++11)
(deprecated in C++20)
(removed in C++26) (10) (since C++11)
(deprecated in C++20)
(removed in C++26) (11) (since C++11)
(deprecated in C++20)
(removed in C++26)

If multiple threads of execution access the same std::shared_ptr object without synchronization and any of those accesses uses a non-const member function of shared_ptr then a data race will occur unless all such access is performed through these functions, which are overloads of the corresponding atomic access functions (std::atomic_load, std::atomic_store, etc.).

Note that the control block of a shared_ptr is thread-safe: different std::shared_ptr objects can be accessed using mutable operations, such as operator= or reset, simultaneously by multiple threads, even when these instances are copies, and share the same control block internally.

1) Determines whether atomic access to the shared pointer pointed-to by p is lock-free.

3) Returns the shared pointer pointed-to by p.

5)

Stores the shared pointer

r

in the shared pointer pointed-to by

p

atomically,

as if

by

p->swap(r)

.

7)

Stores the shared pointer

r

in the shared pointer pointed to by

p

and returns the value formerly pointed-to by

p

, atomically,

as if

by

p->swap(r)

and returns a copy of

r

after the swap.

8) Equivalent to

9) Equivalent to

10,11)

Compares the shared pointers pointed-to by

p

and

expected

.

atomic_compare_exchange_weak_explicit may fail spuriously.

If p is a null pointer, the behaviors of these functions are all undefined.

[edit] Parameters [edit] Exceptions

These functions do not throw exceptions.

[edit] Return value

1) true if atomic access is implemented using lock-free instructions.

2,3) A copy of the pointed-to shared pointer.

4,5) (none)

6,7) A copy of the formerly pointed-to shared pointer.

8-11) true if the shared pointers were equivalent and the exchange was performed, false otherwise.

[edit] Notes

These functions are typically implemented using mutexes, stored in a global hash table where the pointer value is used as the key.

The Concurrency TS offers atomic smart pointer classes atomic_shared_ptr and atomic_weak_ptr as a replacement for the use of these functions.

[edit] Example [edit] Defect reports

The following behavior-changing defect reports were applied retroactively to previously published C++ standards.

DR Applied to Behavior as published Correct behavior LWG 2172 C++11 expected could be a null pointer the behavior is undefined in this case LWG 2980 C++11 empty shared_ptrs were never equivalent equivalent if they store the same pointer value [edit] See also

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4