본문 바로가기
Language/Verilog & SV

[System Verilog] Mailbox?

by VIR&US 2025. 4. 9.
반응형

목차

 

Mailbox?

  • Similar to an unlimited FIFO
  • Semaphore는 key를 이용해 Data Access를 제어하지만, Mailbox는 Data를 가지고 있다가 전달
Name Description
function new (int bound); Mailbox 생성,
bound (> 0)는 mailbox queue의 크기,
bound = 0은 무제한의 mailbox
function int num(); Mailbox에 있는 message 수 반환
task put (singular message); Mailbox에 message를 put,
Mailbox의 공간이 없으면 get() 이전까지 차단
task get
(ref singular message);
Mailbox에서 message 검색,
가져올 메시지가 없으면 put() 이전까지 대기
task peek
(ref singular message);
Mailbox queue에서 message를 제거하지 않고
하나의 message 복사
function int try_put
(singular message);

Mailbox에 message를 put(차단되지 않음),
Mailbox가 가득 차 있는 경우 0 반환
function int try_get
(ref singular message);

Mailbox에서 message 검색(차단되지 않음),
Mailbox가 비어있는 경우 0 반환
function int try_peek
(ref singular message);

Mailbox queue에서 message를 제거하지 않고
하나의 message 복사,

Mailbox가 비어있는 경우 0 반환

 

Example1

 

이해를 돕기 위한 단일 메시지만 보관 가능한 가장 작은 mailbox입니다.
단일 mailbox만 사용하는 경우 예시 code에서 항상 producer가 consumer보다 한단계 앞섭니다.

 

동기화하여 단계당 동시에 실행하고 싶다면, event를 사용하거나, peek() 이 후 get()를 사용하여 맞추거나, 두개의 mailbox를 사용하여 하나는 완료메시지를 전달하는 용도로 code를 작성해야 합니다.

Result1

Example2

Result2

728x90
반응형