0

我简单的“HelloWorld”程序不起作用。程序会打印通常的 SystemC 版权声明,但不会打印“Hello World”字符串)。

SC_METHOD如果我使用(removing calls)编写类似的程序wait,我可以看到打印的消息。

这是什么原因造成的?

    #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;

    }
4

3 回答 3

2

在安装 SystemC 库期间,使用--enable-pthreads选项编译它。这将解决您的问题。

于 2015-07-31T10:30:07.657 回答
1

您的代码在 OS X 上使用 SystemC 2.3.1(来自 Accellera)和 Clang 6.0 对我来说工作正常:我看到两个 hello 打印都来自线程进程。

$ ./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!

我不确定您为什么会看到不同的行为。这可能是您的主机操作系统中的某种 IO 缓冲行为吗?您可以尝试将sc_start()线路更改sc_start(20, SC_NS)为运行有限的时间。

于 2015-03-17T01:12:59.823 回答
0

你的代码对我也很好。也许尝试刷新标准输出的输出缓冲区?使用 endl 而不是 '\n' 或cout << flush

于 2015-05-13T07:11:21.683 回答