But when I remove the comment to enable the uvm_do_with, there is no problem.
I tried to research about uvm_do_with macro and I found out that inside that macro it is creating the item using uvm_create macro.
Can someone please verify this?
And do I need to create the req or just construct it in the function new?
with various flavors for adding constraints to the randomization, disabling randomization, specifying the sequencer and other things. They also allow you to add pre_do and post_do callback methods that the macros call in between start_item() and finish_item().
As we’ve said many times, there is no reason to use the uvm_do macros. There are too many of them to remember, the callbacks add unnecessary complexity, and they hide too much detail that you really should be paying attention to, causing problems like the one you reported.
And there is certainly no reason you would ever want to use BOTH a uvm_do macro and start_item/finish_item.
In short, DO NOT USE THE `uvm_do MACROS.
See Are Macros Evil? DVCon 2011 Best Paper .