Jump to content
Khushi

sc_signal cannot have more than one driver error

Recommended Posts

Hi

I have a use case where multiple threads are writing on a signal port and I get the sc_signal<T> cannot have more than one driver error.

To avoid that I started to use sc_mutex and use lock/unlock., but still I get the same error.

Here is what I tried to reproduce my use case with a small example.

Can you help me to understand what is going wrong even after using mutex and how to avoid this issue.

#include"systemc.h"

using namespace std;
using namespace sc_core;

class module : public sc_module {
    public:
    sc_signal<bool> sig;
    sc_mutex m;
    explicit module(sc_module_name name): sc_module(name),sig("sig"){
        SC_HAS_PROCESS(module);
        SC_THREAD(p1);
        SC_THREAD(p2);
    }
    void p1(){
        while(1){
            wait(10,SC_NS);
            m.lock();
            sig.write(1);
            m.unlock();
        }
    }

    void p2(){
        while(1){
            wait(10,SC_NS);
            m.lock();
            sig.write(0);
            m.unlock();
        }
    }

    ~module(){
    }
};

int sc_main(int, char**){
    module m("m");
    sc_start();
    return 0;
}

Thanks 

Khushi

Share this post


Link to post
Share on other sites

my point is that if multiple threads write to same port at same time than this error make sense but when multiple threads write to same port at different time than it should be ok as there is no race in that case. It is as good as same thread write to that port at different time stamp.

I am trying to understand the logic behind this error when threads are competing for the same resource in different time points.

Share this post


Link to post
Share on other sites
1 minute ago, Khushi said:

Just to add, in my use case it is guaranteed that the different threads write to same port(signal) at different time stamp.

Thanks

Khushi

That still is a problem with SC_ONE_WRITER policy. Quoting from LRM (my emphasis):

Quote

 If the template argument WRITER_POLICY has the value SC_ONE_WRITER, it shall be an error to write to a given signal instance from more than one process instance at any time during simulation.

See the change if you declare sig as:

sc_signal<bool, SC_MANY_WRITERS> sig;

 

Share this post


Link to post
Share on other sites

If you want multiple drivers, use sc_signal_resolved or sc_signal_rv<N>. The reason for SC_ONE_WRITER is to catch errors since the normal use case for sc_signal is single drivers. The SC_MANY_WRITERS was intended to allow one process to initialize and then hand-off to another process. Your use case likely the resolved signal situation. Verilog uses wires for the resolved case. VHDL has you to be more explicit.

Share this post


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