Jump to content
Sign in to follow this  
Deeps

how to find if two threads are trying to operate on a same mutex

Recommended Posts

Hi All,


It would be of great help if someone could tell me how to find if two threads are trying to operate on a same mutex?

I also want to find the entire communication that happens with respect to locks while the program is being run,

I came to know about this forum from some researcher. any inputs will be of immense help.


Regards,
Deepthi

Share this post


Link to post
Share on other sites

You would need to write a wrapper class with debug aids builtin. A sketch might be:

struct debug_mutex
: sc_core::sc_mutex
{
  void lock( void ) override
  {
    auto requester = sc_core::sc_get_current_process_handle();
    INFO( DEBUG, "Attempting lock of mutex " << uint_ptr_t(this) << " from " << requester.name() " at " << sc_time_stamp() );
    this->sc_mutex::lock();
    locked = true;
    locker = requester.name();
    time = sc_time_stamp();
    changed.notify();
  }
  void unlock( void ) override
  {
    auto requester = sc_core::sc_get_current_process_handle();
    this->sc_mutex::unlock();
    time = sc_time_stamp();
    locked = false;
    locker = "";
    changed.notify();
  }
  // Attributes
  bool locked{ false };
  sc_event changed;
  sc_time time;
  string locker;
};

I have not tested above.

NOTE: I have a macro INFO that issues an appropriate SC_REPORT_INFO_VERB with the above indicated syntax. Replace with your own. Never use std::cout or std::cerr if coding SystemC.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×