Untitled
unknown
plain_text
10 months ago
731 B
6
Indexable
#include <mutex>
#include <shared_mutex>
#include <condition_variable>
class ReadWriteLock {
std::shared_mutex mtx;
public:
// Constructor
ReadWriteLock() {
}
// Acquire a read lock - multiple readers allowed
void lockRead() {
mtx.lock_shared();
}
// Release a read lock
void unlockRead() {
mtx.unlock_shared();
}
// Acquire a write lock - exclusive access
void lockWrite() {
mtx.lock();
}
// Release a write lock
void unlockWrite() {
mtx.unlock();
}
// Delete copy constructor and assignment operator
ReadWriteLock(const ReadWriteLock&) = delete;
ReadWriteLock& operator=(const ReadWriteLock&) = delete;
};Editor is loading...
Leave a Comment