当前位置:网站首页>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
边栏推荐
猜你喜欢
随机推荐
Tidb database characteristics summary
3D打印机穿线:5种简单的解决方案
Differences between in and exists in MySQL
浅谈SIEM
指数法和Random Forest实现山东省丰水期地表水体信息
Ant new village is one of the special agricultural products that make Tiantou village in Guankou Town, Xiamen become Tiantou village
The row and column numbers of each pixel of multi-source grid data in the same area are the same, that is, the number of rows and columns are the same, and the pixel size is the same
机械臂速成小指南(六):步进电机驱动器
PLA not pasted on the bed: 6 simple solutions
Pit of kotlin bit operation (bytes[i] and 0xff error)
DHT11 温湿度传感器
C language beginner level - realize the minesweeping game
PLA不粘貼在床上:6個簡單的解决方案
UOW of dev XPO comparison
OpenGL es: (5) basic concepts of OpenGL, the process of OpenGL es generating pictures on the screen, and OpenGL pipeline
蚂蚁新村田头村变甜头村 让厦门灌口镇田头村变甜头村的特色农产品之一是
【ManageEngine卓豪】局域网监控的作用
Arcserver password reset (account cannot be reset)
DEV XPO对比之XAF BO
【ManageEngine卓豪 】助力世界顶尖音乐学院--茱莉亚学院,提升终端安全