简体   繁体   English

在Systemverilog中使用进程间同步

[英]Using interprocess synchronization in Systemverilog

I need to model some portion of my hardware in systemverilog and it kind of looks like following: 我需要在systemverilog中对硬件的某些部分进行建模,如下所示:

I can have two treads -(SV task) running in parallel. 我可以有两个踏板-(SV任务)并行运行。

Thread:

1. get_resource_from_manager()  [sema.get(1) ??]
2. repeat(until_finish)
3.   do_work()
4.   give_contorl_to_thread1() [sema.put(1) ??]
5.   wait_for_thread1_to_return_control() [sema.get(1) ??]
6.   continue_work()
7. endrepeat
8. do_some_cleanup()
9. exit()

Both Threads do the same work. 两个线程执行相同的工作。 I am thinking about using semaphore. 我正在考虑使用信号量。 I've never used it before. 我以前从未用过。 Is it a valid assumption/fact that the thread will block at line 5? 线程将在第5行阻塞,这是一个有效的假设/事实吗? What I wanted to achieve is, thread1 will give up resource to thread2 by using semaphore put() in line 4 -> thread 2 will pick up this resource and do it's work and eventually release it using put. 我想要实现的是,线程1将通过在第4行中使用信号量put()来将资源分配给线程2->线程2将获取该资源并完成工作,最后使用put释放它。 In between this time, thread1 will be waiting on blocking get() call at line 5. 在这段时间之间,线程1将在第5行等待阻塞get()调用。

Yes if one thread gets the semaphore, the other one will be blocked. 是的,如果一个线程获得了信号量,则另一线程将被阻止。 You need to define the semaphore as: 您需要将信号灯定义为:

 semaphore  sema = new(1);

Here is a working example similar to what you are looking for. 是一个与您正在寻找的相似的工作示例。 In order for the two tasks to run concurrently, they should be called from two parallel bodies, such as inside a fork-join block. 为了使两个任务同时运行,应该从两个并行主体(例如在fork-join块内部)调用它们。 Also, notice that semaphores are not synthesizable by common synthesis tools. 此外,请注意,信号量无法通过常用的综合工具进行综合。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM