简体   繁体   中英

System Verilog DPI - Running parallel threads one in cpp and other in SV

I have a fork-join_none block in forever loop in SV which has two threads. One thread is a call to a task in SV itself. The other thread is a call to a function imported from CPP. Is it possible to run these two threads in parallel?

I tried this but what's happening is once the CPP function is called control is not returning back to SV side making the other thread in SV not working.

How to run these two in parallel???

A function does not consume simulation time. In SystemVerilog, to get threads running in parallel, both need to block at some point to allow the other thread to run.

When using the DPI, C/C++ code has no concept of consuming time. What you need to is import your cpp code as a task, and then at some point it needs to call an exported SystemVerilog task to block. So it's possible to use the DPI to achieve parallelism in C calling exported tasks to SystemVerilog. However, the notion of time is very different in the HDL and C worlds. See my DVCon paper Easy Steps Towards Virtual Prototyping using the SystemVerilog DPI which discusses some of the issues of tracking time between the two domains.

short answer is: no. Verilog supports a single-threaded simulation model only. Verilog threads never run in parallel. So, you cannot do it.

Nothing can prevent you from using parallel threads as soon as you are inside ac/c++ call (dpi), however you should not attempt calling any exported verilog functions from from a parallel threads without proper synchronization, in particular from detached threads. The simulation engine is most likely not thread safe.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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