Run Code
|
API
|
Code Wall
|
Users
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
UB mutex lock
#include <memory> #include <mutex> #include <vector> #include <iostream> #include <thread> struct Test{ std::mutex mutex; std::vector<int> v = { 1,2,3,4,5}; auto fun(int n){ mutex.lock(); return std::shared_ptr<int>(v.data() + n, [this](...){mutex.unlock();}); } }; int main(){ Test tt; auto a = tt.fun(1); std::cout << *a << std::endl; auto b = tt.fun(2); std::cout << *b << std::endl; return 0; }
run
|
edit
|
history
|
help
0
Please
log in
to post a comment.
BST to DLL
template
Power of an element
remove_if_30-Seconds-of-C++
Rev Fact WIP
NWD, algorytm Euklidesa
fgm
1234
execution of constructor and destructor
cppPyClassMethod
Please log in to post a comment.