Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

produce the double lock/unlock error #102

Merged
merged 3 commits into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cache/coherence_multi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ class OuterCohPortMultiThreadT : public OPUC
bool hit = cache->hit(addr, &ai, &s, &w, Priority::probe);
if(hit){
std::tie(meta, data) = cache->access_line(ai, s, w);
cache->lock_line(ai, s, w);
/** It is possible that higher priority behaviors have caused the meta to change, so need check again */
if(!meta->is_valid() || meta->addr(s) != addr){
cache->unlock_line(ai, s, w);
Expand Down
33 changes: 28 additions & 5 deletions cache/metadata.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
#include <string>
#include "util/concept_macro.hpp"
#include <mutex>

#ifndef NDEBUG
#include <atomic>
#include <thread>
#include <cassert>
#endif

class CMDataBase
{
Expand Down Expand Up @@ -220,11 +219,35 @@ using MetadataDirectory = MetadataMixer<AW, IW, TOfst, MT>;
template <typename MT> requires C_DERIVE<MT, CMMetadataCommon>
class MetaLock : public MT {
std::mutex mtx;

#ifndef NDEBUG
// verify no double lock or unlock
std::hash<std::thread::id> hasher;
std::atomic<uint64_t> locked;
#endif

public:
MetaLock() : MT() {}
virtual ~MetaLock() {}
virtual void lock() { mtx.lock(); }
virtual void unlock() { mtx.unlock(); }
virtual void lock() {
#ifndef NDEBUG
uint64_t thread_id = hasher(std::this_thread::get_id());
assert(locked.load() != thread_id || 0 ==
"This cache line has already be locked by this thread and should not be locked by this thread again!");
#endif
mtx.lock();
#ifndef NDEBUG
locked = thread_id;
#endif
}
virtual void unlock() {
#ifndef NDEBUG
assert(locked.load() != 0 || 0 ==
"This cache line has already be unlocked and should not be unlocked again!");
locked = 0;
#endif
mtx.unlock();
}
};

#endif
2 changes: 1 addition & 1 deletion util/monitor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,8 @@ class SimpleTracerMT : public SimpleTracer
{
PrintPool pool;
std::thread print_thread;
std::hash<std::thread::id> hasher;
virtual void print(std::string& msg) {
std::hash<std::thread::id> hasher;
uint16_t id = hasher(std::this_thread::get_id());
std::string msg_ext = (boost::format("thread %04x: %s") % id % msg).str();
pool.add(msg_ext);
Expand Down
1 change: 0 additions & 1 deletion util/multithread.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,5 +108,4 @@ class PendingXact<false> {
};



#endif
Loading