Javia1492
Javia1492

Reputation: 892

SC_THREAD's wait() statement does not block OS thread

I was having some issue synchronizing threads in my larger program and noticed that some of my wait statements were never returning so I decided to just write a simple thread to test the function of wait and noticed that its getting completely ignored at the SC_SEC level. Here's the example I am running:

void Transmit::Tx(){
    time_t t1, t2;
    while (1){
        t1 = time(NULL);
        wait(10, SC_SEC);
        t2 = time(NULL);
        cout << t2 - t1 << endl;
    }
}

My thread is free running and what i expect is the thread to halt for 10 seconds and resume and the printout should be 10 everytime, but i see 0 and its not printing every 10 seconds, its printing like its ignoring my wait statement. I have no idea what I am doing wrong here. I am following this for my understanding of wait but I don't see what the issue is.

Likewise, when I tried testing with 2 threads which one writes data to a fifo, waits some time, and the other reads the data from the fifo and waits some time, I noticed that the threads never returned from the wait.

Upvotes: 0

Views: 483

Answers (1)

AmeyaVS
AmeyaVS

Reputation: 1034

Are you trying to model a Hardware design using SystemC or trying to use SystemC for software modelling? It seems you have mixed up the contexts.

SystemC is used primarily to modelling Hardware Design (similar to VHDL and Verilog).

The timing notion you observe in SystemC context does not relate to the real-world time at all.

Of course you will always observe near zero-time execution time when are switching threads in SystemC, as it just switches context of execution to other threads and the SystemC kernel just synchronizes the Virtual Time(i.e. simulation time) to model time(virtual time) based event in the SystemC kernel.

Upvotes: 1

Related Questions