当前位置:网站首页>SystemVerilog learning-09-interprocess synchronization, communication and virtual methods
SystemVerilog learning-09-interprocess synchronization, communication and virtual methods
2022-07-01 06:13:00 【Vuko-wxh】
brief introduction
All threads in the test platform need to synchronize and exchange data .
— Threads waiting for another , For example, the verification environment needs to wait for all incentives to end 、 The simulation can be ended only after the comparison .
For example, the monitor needs to send the monitored data to the comparator , The comparator needs to get data from different caches for comparison .
event event
Can pass event To declare a name event Variable , And trigger it . The name event Can be used to control the execution of a process . Can pass -> To trigger an event . Other processes waiting for this event can pass through @ Operator or wait() To check event Trigger status to complete .
wait_order()
wait_order Can keep the process waiting , Until the event in the parameter list event Complete from left to right in order . If the events in the parameter list are triggered but not in the required order , Then the wait operation will fail .
wait_order (a,b,c);
wait_order (a,b,c) else $display ( "Error: eventsout of order" );
bit success;
wait_order(a,b,c) success = 1; else success = 0 ;
Flag language (semaphore)
Semaphores conceptually , It's a container . When creating flags , They are assigned a fixed number of keys .· Processes that use flags must first obtain their keys , To continue . The number of keys in the semaphore can be multiple , There can also be multiple processes waiting for the semaphore key . Semaphores are usually used for mutual exclusion , Access control of shared resources , And basic synchronization .
Create flags , And assign keys to them in the following way :
semaphore sm;
sm = new ();
Create a flag with a fixed number of keys : new (N = 0).
Get one or more keys from the semaphore ( Blocking type ) : get (N = 1).
Return one or more keys to the semaphore : put (N = 1).
Try to get one or more keys without blocking ( Non blocking ) : try_get (N = 1).
semaphore: :new()
new () The prototype is as follows :function new (int keycount = 0) ;
keycount Specifies the number of keys initially assigned to the semaphore . When more keys are put into the flag , The number of keys can exceed the initial keycount Number , Instead of deleting .
keycount The default value is 0.new () Function returns a handle to the semaphore .
semaphore: : put()
put () Method is used to return the number of keys to the semaphore .
put () The prototype is as follows :function void put (int keycount = 1) ;
keyCount Specifies the number of keys to return to the semaphore . The default value is 1. call semaphore.put() Function time , The specified number of keys will return to the flag . If other processes are already waiting for the flag , The process should return... With a sufficient number of keys .
semaphore: :get()
get () Method is used to obtain a specified number of keys from the semaphore .
get () The prototype is as follows : task get (int keycount = 1) ;
keyCount Specifies the number of keys required to obtain from the semaphore , The default value is 1. If the specified number of keys is available , Then the method returns and continues to execute . If the specified number of keys is insufficient , The process will block , Until there are enough keys . The waiting queue for flags is first in first out (FIFO), That is, those who wait in line for the flag first will get the key first .
semaphore::try _get()
try get () Method is used to obtain a specified number of keys from a semaphore , But it won't be blocked .
try get () The prototype is as follows :function int try_get (int keycount = 1) ;
keyCount Specifies the number of keys required to obtain from the semaphore , The default value is 1. If the specified number of keys is available , Then the method returns a positive number and continues . If the specified number of keys is insufficient , Then the method returns 0.
mail mailbox
mail mailbox It can exchange information between processes , Data can be written to the mailbox by a process , And then another process gets . Mailboxes can be created with limited capacity , Or unlimited . When the mailbox is full , Subsequent rewriting will be suspended , Until the mailbox data is read from it , Make the mailbox have space before you can continue to write . A mailbox that does not limit its capacity will not suspend writing to the mailbox .
Built in method of mailbox
- Create mailbox : new().
- Write information to mailbox : put().
- Try to write to the mailbox, but it won't block : try_put().
- pick up information : get() At the same time, the data will be taken out ,peek() No data will be taken out .
- Try to get data out of the mailbox, but it won't block : try _get()/try_peek().
- Number of mailbox information obtained : num().
mailbox::new()
You can limit or not limit the size of the mailbox when you create it .
function new (int bound = 0) ;
By default , If you don't pass in parameters ,bound The default value is 0, Indicates unlimited mailbox size , If the value passed in is greater than 0, So, it means the maximum capacity of the mailbox .bound Expected positive number , If it's not negative , The system will prompt warnings and unexpected behavior .
mailbox::num()
num() The current number of messages in the mailbox will be returned .
Can combine num() And get() perhaps put(), prevent get()/put() Method is blocked when the mailbox is empty or full .
mailbox: :{put(), try_put()}
task put( singular message) ;
function int try_put( singular message) ;
put() The information will be FIFO Write to the mailbox in the order of , If the mailbox is full at this time , be put() The task will hang , Until the mailbox has new space for messages .try_put() I will also follow FIFO Write to mailbox sequentially , There will be no blockage . If the mailbox is full , Write failed , return 0; If the mailbox is not full , Write success , return 1.
mailbox ::{get(), try_get()}
task get( ref singular message ) ;
function int try_get( ref singular message ) ;
get() Will take the information out of the mailbox , If the mailbox is empty at this time , be get() The task will hang , Until there is a message in the mailbox that can be read , The task will return . This method will remove the read message from the mailbox .
try_get() It will also take the information out of the mailbox , It's just that the function won't block . If the mailbox is empty , Read failed , return 0; If the mailbox is not empty , Then the reading is successful , return 1. This method will also remove the read message from the mailbox .
mailbox: :{peek(), try_peek()}
task peek ( ref singular message ) ;
function int try_peek ( ref singular message );
peek() Will copy the information from the mailbox , If the mailbox is empty at this time , be peek() The task will hang , Until there is a message in the mailbox that can be copied , The task will return . This method does not remove the read message from the mailbox .
try_peek() The information will also be copied from the mailbox , It's just that the function won't block . If the mailbox is empty , Then the copy fails , return 0; If the mailbox is not empty , The copy is successful , return 1. This method also does not remove the copied message from the mailbox .
Parameterized mailbox
Default mailbox , Without specifying the storage type , Can store any type of data . To avoid runtime errors and type mismatches , It is suggested that when declaring the mailbox , Specify the type of storage for it .
This way of parameterizing the mailbox allows you to check for type mismatches at compile time .
typedef mailbox #(string) s_mbox;
s _mbox sm = new ;
string s;
sm.put ("he1lo");
...
sm.get( s ); // s <- "he1lo"
Virtual method
Class member methods can be modified virtual( Virtual method ). Virtual method is a basic polymorphism (polymorphic) structure . A virtual method can override the method with the same name of the base class . Virtual methods declared in parent and child classes , Its method name 、 Parameter name 、 The parameter direction should be consistent . When calling a virtual method , It will call the method whose handle points to the object , Regardless of the handle type .
reference
- Verification of West circuit department PPT
边栏推荐
- Retention rate of SQL required questions
- Talking from mlperf: how to lead the next wave of AI accelerator
- OpenGL es: (3) EGL, basic steps of EGL drawing, eglsurface, anativewindow
- Top 10 Free 3D modeling software for beginners in 2022
- 端口扫描工具对企业有什么帮助?
- IT服务管理(ITSM)在高等教育领域的应用
- OpenGL es: (4) detailed explanation of EGL API (Continued)
- pycharm 配置jupyter
- 【ManageEngine卓豪】网络运维管理是什么,网络运维平台有什么用
- 数据库er图组成要素
猜你喜欢

JDBC database operation

TiDB单机模拟部署生产环境集群(闭坑实践,亲测有效)
![kotlin位运算的坑(bytes[i] and 0xff 报错)](/img/2c/de0608c29d8af558f6f8dab4eb7fd8.png)
kotlin位运算的坑(bytes[i] and 0xff 报错)

【ManageEngine卓豪】网络运维管理是什么,网络运维平台有什么用

excel初级应用案例——杜邦分析仪

分布式锁实现

Geoffrey Hinton: my 50 years of in-depth study and Research on mental skills

基于LabVIEW的计时器
![[note] e-commerce order data analysis practice](/img/03/367756437be947b5b995d5f7f55236.png)
[note] e-commerce order data analysis practice

DHT11 temperature and humidity sensor
随机推荐
浏览器端保存数据到本地文件
基于LabVIEW的计时器
【自动化运维】自动化运维平台有什么用
FPGA - 7系列 FPGA内部结构之Clocking -01- 时钟架构概述
PLA not pasted on the bed: 6 simple solutions
【企业数据安全】升级备份策略 保障企业数据安全
DEV XPO对比之XAF BO
Geoffrey Hinton: my 50 years of in-depth study and Research on mental skills
Stack Title: parsing Boolean expressions
Pit of kotlin bit operation (bytes[i] and 0xff error)
Projects and dependencies in ABP learning solutions
How does MySQL store Emoji?
HDU - 1501 zipper (memory deep search)
Highmap gejson data format conversion script
Minio error correction code, construction and startup of distributed Minio cluster
蚂蚁新村田头村变甜头村 让厦门灌口镇田头村变甜头村的特色农产品之一是
解决麒麟V10上传文件乱码问题
68 Cesium代码datasource加载czml
Arcserver password reset (account cannot be reset)
Transformer le village de tiantou en un village de betteraves sucrières