Jump to content

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


Deeps

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

Link to comment
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.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...