编辑
2024-03-17
SystemC
00
请注意,本文编写于 360 天前,最后修改于 360 天前,其中某些信息可能已经过时。

目录

并发
Concurrency.cpp
结果

并发

SystemC 使用模拟过程来模拟并发性。这不是真正的并发执行。 当多个进程被模拟为同时运行时,在特定时间仅执行一个进程。但是,模拟时间保持不变,直到所有并发进程完成其当前任务。 因此,这些进程在同一“模拟时间”上同时运行。

Concurrency.cpp

c++
#include <systemc> using namespace sc_core; SC_MODULE(CONCURRENCY) { SC_CTOR(CONCURRENCY) { // 构造 函数 SC_THREAD(thread1); // 寄存器线程1 SC_THREAD(thread2); // 寄存器线程2 } void thread1() { while(true) { // 无限循环 std::cout << sc_time_stamp() << ": thread1" << std::endl; wait(2, SC_SEC); // 2 秒后再次触发 } } void thread2() { while(true) { std::cout << "\t" << sc_time_stamp() << ": thread2" << std::endl; wait(3, SC_SEC); } } }; int sc_main(int, char*[]) { CONCURRENCY concur("concur"); // 定义对象 sc_start(10, SC_SEC); // 模拟10秒 return 0; }

结果

SystemC 2.3.3-Accellera --- Oct 4 2020 22:59:38 Copyright (c) 1996-2018 by all Contributors, ALL RIGHTS RESERVED 0 s: thread1 0 s: thread2 2 s: thread1 3 s: thread2 4 s: thread1 6 s: thread2 6 s: thread1 8 s: thread1 9 s: thread2

本文作者:古月流新

本文链接:

版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!