Jump to content

import statement location effects on random stability


Recommended Posts

"import" just makes the symbols of the package visible. doing so inside or outside of a package can change what is being included/referenced and might change initialization order and therefore randomization. in general you should

 

- only import within a scope (such as in a package/module/program) and not use the global scope

- avoid (static) initialization races

- protect areas which you want rand-stable with code (or use uvm for that)

Link to comment
Share on other sites

You must import a package or explicitly reference a symbol in a package if you want to use it. Importing a symbol just means you don't have to prefix the symbol with the package name (i.e. pkg_name::symbol_name)

 

The biggest problems we see with packages related to random stability are caused by static variable initializations that call class constructors. You either have a class variable in your package that is statically initialized, or there is a static member of a class that is statically initialized. The ordering of these initializations is not deterministic. (http://www.parashift.com/c++-faq/static-init-order.html). What makes it even worse is the unanswered question: "if I compile my a package and nobody references it, does it exist?" meaning do the static variables exist and call functions/constructors as part of their initialization. Tools have different ways of handling this.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...