RegisterLogin  
Update Profile
   
You are here: Forum  
Minimize 
SVUG Community Forum
Subject: Original Post: gsw73
Prev Next
You are not authorized to post a reply.

Author Messages
forumUser is Offline

Posts:0

04/27/2007 5:40 PM  

I created a queue in my Env class. I want to pass the queue by reference to other objects I create in my Env class so that each object is referring to the same queue. However, it seems that my queue is simply copied from the Env object to the other objects i.e., I can pop elements from the queue in one object, but they still remain on the the queue in other objects. The "ref" I've used in front of the queue argument in my function seems to have no effect... thoughts?

Thanks,

-Greg

------
bit [ 6:0 ] my_Q[ $ ]
function new( ..., ref bit [ 6:0 ] myQ[ $ ], ... );

my_Q = myQ;

endfunction

forumUser is Offline

Posts:0

04/27/2007 5:40 PM  

Hi,

I dont thing you can use the queues like this,even though u pass the Q like this the same Q will be accessed.you r right there will be no effect you can see on Q's.
so i think it will not work this way, you may have to use separate Q's. by somehow if u r able to achive what u want,plase do share the info.

thanks
Manmohan

forumUser is Offline

Posts:0

04/27/2007 5:40 PM  

Greg,
To the best of my knowledge, what you're doing is semantically correct and should hence work. Perhaps reference arguments aren't fully supported yet by all simulators. Have you checked the release notes of your preferred SystemVerilog simulator?

If you find that there is truly something we are overlooking here, please be sure to check back into the forum to share this.

Regards,
Hans

forumUser is Offline

Posts:0

04/27/2007 5:47 PM  

Greg,

A 'ref' in a function's formal argument declaration does not give you a handle to that argument. It means that a reference to the formal argument is really a reference to the actual argument instead of a being a copy of it. The statement my_Q = myQ will create a copy in either case. A ref argument is just an optimization when used with a function; it's more useful with a blocking task.

What you probably want to do is define your queue as a member of a class and pass a handle to an instance of that class into your constructor.

Dave

forumUser is Offline

Posts:0

04/27/2007 5:47 PM  

Yes that makes sense now: the statement my_Q = myQ causes the copying to take place, not the actual to formal argument passing in this case. If 'ref' was not used than copying would also happen upon argument passing, right?

Thanks for the clarification, Dave.

Hans

forumUser is Offline

Posts:0

04/27/2007 5:48 PM  

I see now... I'm still getting my head around the subtle differences between C++ pointers and SystemVerilog handles and ref-s.

I did as suggested and created a class which holds the required queue. I'm then able to pass the handle of the instantiated queue-class object around such that it becomes a shared resource for various threads (along with a semaphore so they don't stomp on each other). This has lots of other benefits since the init of the queue neatly takes place within its new() constructor and adding other elements to the class later which might be required becomes trivial.

Thanks for the feedback.

-Greg

You are not authorized to post a reply.



ActiveForums 3.7
  

 Copyright 2008 by SystemVerilog User Group Contact Us    Privacy Statement