Ankit10 Posted October 16, 2021 Report Share Posted October 16, 2021 Hi, I was experimenting with sc_fifo with the following producer-consumer code, my question is that why is the consumer not reading the values beyond 0? is it that the latest notification for sc_event at 1 has cancelled out the previous one at 0? how do I remedy this? do I have sc_fifo producer consumer dependent on clk edge only? sc_fifo_test(sc_module_name name😞sc_module(name),clk("clk",1,SC_SEC),f1(2),f2(2),f3(2){ SC_THREAD(generator1); sensitive<<clk.posedge_event(); dont_initialize(); SC_THREAD(consumer1); sensitive<<f1.data_written_event(); dont_initialize(); }; void generator1() { int v = 0; while(true) { wait(); f1.write(v); std::cout << sc_time_stamp() << ": generator1 writes " << v++ << " @delta cycle "<<sc_delta_count()<<std::endl; wait(1,SC_SEC); } } void consumer1() { int v = -1; while(true) { wait(); f1.read(v); std::cout << "\t"<<sc_time_stamp() << ": consumer1 reads " << v << " @delta cycle "<<sc_delta_count()<<std::endl; wait(2,SC_SEC); } } I get the following output execution phase begins @ 0 s 1 s: generator1 writes 0 @delta cycle 4 2 s: generator1 writes 1 @delta cycle 8 2 s: consumer1 reads 0 @delta cycle 9 3 s: generator1 writes 2 @delta cycle 12 execution phase ends @ 10 s 10 s: Cleanup: desctructor Quote Link to comment Share on other sites More sharing options...
Ankit10 Posted October 24, 2021 Author Report Share Posted October 24, 2021 Hi @Admin , please let me know if my theory holds water? Quote Link to comment Share on other sites More sharing options...
maehne Posted October 28, 2021 Report Share Posted October 28, 2021 Your example code is not fully self-contained. Nevertheless, I wonder why you are waiting for 2 s at the end of each loop iteration in your consumer thread. The wait() call at the beginning should be sufficient. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.