Talz Posted March 15, 2023 Report Share Posted March 15, 2023 Hi, this is a general question about data synchronization in systemc between threads. lets say i have a module with a global variable (e.g int) and two SC_THREAD that both read and write from it. does systemc ensures somehow that the memory updates of one of the thread is visible to another? usually i would use volatile/fence/atomic that insures the compiler reads the value from memory and not from register but i did not find any instances of this in systemc code or in systemc examples. can i assume a more standard way to solve this is to use sc_signal<int> and do read()/write() operations on it? what happens if i want to use a large struct and i want to update only a small part of it? it seems a bit expensive to read/write the entire struct each time. Quote Link to comment Share on other sites More sharing options...
Eyck Posted March 15, 2023 Report Share Posted March 15, 2023 SystemC guarantees sequential execution of threads so that no expicit syncronization mechanisms are needed. Please consult the LRM for further information. SystemC does not guarantee any particular order of execution of threads so reading and writing from different SC processes to native datatypes may give surprising results e.g. if both processes are sensitive to the same event. In this case you should use a signal or any other primitive channel which uses a defered updatre scheme (e.g. sc_fifo). Quote Link to comment Share on other sites More sharing options...
David Black Posted March 15, 2023 Report Share Posted March 15, 2023 Use channels or sc_event to synchronize. Channels usually incorporate some form of synchronization using sc_event within their implementation. Channels facilitate regulated communication between processes. As @Eycksaid, you have exclusive non-prememptive control over data at the time your SystemC process executes. You give up that control by yielding either with a call to wait() in SC_THREAD or returning from an SC_METHOD. This rule only applies to SystemC-processes. OS-processes (e.g., std::thread ) are an entirely different matter, and require care since SystemC is not OS thread-safe in general. Also, avoid global variables like the plague (or Covid). Shared channels (possibly via sc_port/sc_export) are fine. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.