Can we create a new category named Development? #440
Replies: 3 comments 10 replies
-
@stefanos82 Lines 416 to 423 in d58a17a If the same functionality can be achieved using the standard library, I don't see any issue in changing it. But didn't find a way to do it when I wrote that section, that was however a while ago and it's quite possible I missed something. |
Beta Was this translation helpful? Give feedback.
-
By all means I'm no expert in POSIX Threads nor in modern C++; but I'm doing my best to learn the deep parts of this language and I have to admit, I'm new to modern C++'s concurrency support. I have found an example online which seems like it produces what you would expect it to do via signals: https://godbolt.org/z/YvEhzf1c3 |
Beta Was this translation helpful? Give feedback.
-
One example I have found online that demonstrates how to resolve deadlocks with modern features (scoped_lock) looks like this: #include <iostream>
#include <chrono>
#include <mutex>
#include <thread>
struct CriticalData
{
std::mutex mut;
};
void deadLock(CriticalData& a, CriticalData& b)
{
std::cout << "Thread: " << std::this_thread::get_id() << " first mutex" << '\n';
std::this_thread::sleep_for(std::chrono::milliseconds(1));
std::cout << "Thread: " << std::this_thread::get_id() << " second mutex" << '\n';
std::cout << "Thread: " << std::this_thread::get_id() << " get both mutex\n";
std::scoped_lock(a.mut, b.mut);
// do something with a and b
}
int main()
{
CriticalData c1;
CriticalData c2;
std::thread t1([&]{deadLock(c1,c2);});
std::thread t2([&]{deadLock(c2,c1);});
t1.join();
t2.join();
std::cout << '\n';
} |
Beta Was this translation helpful? Give feedback.
-
@aristocratos It would help for development discussion(s) since we have no Discord / IRC / other channel as our medium for real-time discussions.
I have questions about POSIX Thread versus Concurrency Library support since C++11 and onward that we could use instead, especially C++20's
std::jthread
thatBeta Was this translation helpful? Give feedback.
All reactions