0

My simple "HelloWorld" program does not work. The programs prints the usual SystemC copyright notice, but not the "Hello World" string).

If I write a similar program using SC_METHOD (removing wait calls), I can see the printed message.

What causes this?

    #include <iostream>
    #include "systemc.h"

    SC_MODULE(stim)
    {
        sc_in<bool> Clk;

        void StimGen()
        {
            cout << "Hello World!\n";
            wait();
            cout << "Hello again, world!\n";
            wait();
        }
        SC_CTOR(stim)
        {
            SC_THREAD(StimGen);
            sensitive << Clk.pos();
        }
    };


    int sc_main(int argc, char* argv[])
    {
        sc_clock TestClk("clk", 10,SC_NS);

        stim Stim1("Stimulus");
        Stim1.Clk(TestClk);

        sc_start();  // run forever

        return 0;

    }
  • Thanks for the answe, but it looks like I solved the issue. There was an installation problem. Re-installing using option --enable-pthreads while configuring the installation solved the problem – Dario Socci Mar 18 '15 at 23:06

3 Answers3

2

During installation of SystemC libraries, compile it with --enable-pthreads option. This will resolve your issue.

CrazyGeek
  • 36
  • 4
1

Your code works fine for me using SystemC 2.3.1 (from Accellera) and Clang 6.0 on OS X: I see both hello prints coming from the thread process.

$ ./main
        SystemC 2.3.1-Accellera --- Nov 29 2014 15:29:06
        Copyright (c) 1996-2014 by all Contributors,
        ALL RIGHTS RESERVED
Hello World!
Hello again, world!

I'm not sure why you are seeing different behavior. Could it be some sort of IO buffering behavior in your host OS? You could try changing the sc_start() line to sc_start(20, SC_NS) to run for a bounded amount of time.

DarrylLawson
  • 732
  • 3
  • 9
0

Your code works fine for me, too. Maybe try to flush the output buffer of stdout? Use endl instead of '\n' or cout << flush

Hsu Hau
  • 604
  • 7
  • 16