# Is there any difference between @cb and @posedge IF.clk

**URL:** <https://verificationacademy.com/forums/t/is-there-any-difference-between-cb-and-posedge-if-clk/30032>\
**Category:** SystemVerilog\
**Tags:** SystemVerilog, clocking-block-event\
**Created:** [October 15, 2014, 4:46am UTC](https://verificationacademy.com/forums/t/is-there-any-difference-between-cb-and-posedge-if-clk/30032 "2014-10-15T04:46:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jibin](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/j/ecae2f/32.png) [@jibin](https://verificationacademy.com/forums/u/jibin)\
**Post date:** [October 15, 2014, 4:46am UTC](https://verificationacademy.com/forums/t/is-there-any-difference-between-cb-and-posedge-if-clk/30032/1 "2014-10-15T04:46:27Z")

</div>

Hi forum,

For a SV interface with a clocking block (code below), Is there any difference between following two expressions?  
Is there a possibility that these two events could be triggered at different time steps or in different regions of same time step ?

Expression 1) @( posedge IF.clk ) ( wait on posedge clk )  
Expression 2) @ IF.cb ( wait on clocking block event which is posedge clk )

interface example ;  
logic clk ;  
logic enable;

clocking cb @(posedge clk )  
default input #1 output #0;  
output enable ;  
endclocking

endinterface

virtual example IF ;

Thanks  
Jibin

---

<div class="post-metadata">

**Author:** ![dave\_59](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/dave_59/32/4499_2.png) [@dave\_59](https://verificationacademy.com/forums/u/dave_59)\
**Post date:** [October 15, 2014, 5:37am UTC](https://verificationacademy.com/forums/t/is-there-any-difference-between-cb-and-posedge-if-clk/30032/2 "2014-10-15T05:37:46Z")

</div>

Yes there is a difference, and my recommendation is: when interacting with clocking blocks, only use the clocking block event **@IF.cb** as the synchronizing event. That includes not using the **wait()** statement or any other **@IF.cb.variable** expressions.

There are two reasons fort this recommendation.

There is a race condition if you use the @(posedge clk) and try to read a sampled clocking block variable. The race is between reading the old sampled value and the new sampled value. This is describe in a note in section _14.4 Input and output skews_ of the 1800-2012 LRM.

Although not explicitly stated in the LRM, a consequence of eliminating the above race is that because clocking block event comes after all clocking block variables are updated, if you wait on a clock block variable followed by a wait on a clocking block event, both event may occur in the same time slot. so write your code as

```verilog
@(IF.cb iff !IF.CB.reset); // instead of wait (!IF.cb.reset)
...
@(IF.cb) // guaranteed to be 1 cycle later.

```

---

<div class="post-metadata">

**Author:** ![jibin](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/j/ecae2f/32.png) [@jibin](https://verificationacademy.com/forums/u/jibin)\
**Post date:** [October 16, 2014, 4:34am UTC](https://verificationacademy.com/forums/t/is-there-any-difference-between-cb-and-posedge-if-clk/30032/3 "2014-10-16T04:34:47Z")

</div>

_In reply to [dave\_59](https://verificationacademy.com/forums/t/is-there-any-difference-between-cb-and-posedge-if-clk/30032/2):_

Thanks Dave

---

<div class="post-metadata">

**Author:** ![Phill\_Ferg](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/p/d26b3c/32.png) [@Phill\_Ferg](https://verificationacademy.com/forums/u/Phill_Ferg)\
**Post date:** [October 20, 2014, 7:24am UTC](https://verificationacademy.com/forums/t/is-there-any-difference-between-cb-and-posedge-if-clk/30032/4 "2014-10-20T07:24:58Z")

</div>

_In reply to [jibin](https://verificationacademy.com/forums/t/is-there-any-difference-between-cb-and-posedge-if-clk/30032/3):_

Dave,

does this assume that the reset is synchronous? If not, are there any reccomendations on handling asynchronous resets with clocking blocks?

thanks
