1

Recently, I am studying systemc and have a question on semaphore channel.

I found an example on asic world (http://www.asic-world.com/systemc/channels3.html) but have a little confused.

At the first 1ns for this example, the first process bus_semaphore() works and can print out two lines "@1 ns ....". At the same time, the semaphore value (bus) changes into 2 (bus.post()) and then wait for the next clock posedge.

For the second process, do_read(), also at the 1ns, the first "@" line can be printed out normally, but then what about the trywait() in the next if-statement? The first and second process should be executed simultaneously, that is to say we cannot determine whether the trywait() executes before or after the bus.post() statement of the first process, so we don't know if the second "@" line of the second process will be printed out.

But the answer shown at the bottom of the page means that the trywait() will execute after the bus.post() executes so that the second "@..." statement will be printed out. How can I be sure that the trywait() will executed after the bus.post()'s execution?

Thanks in advance!

Wayne
  • 33
  • 1
  • 2
  • 9

2 Answers2

1

I think I've figured it out. The order of processes defined in SC_CTOR is really important which is reverse order of definitions in SC_CTOR.

Wayne
  • 33
  • 1
  • 2
  • 9
1

You're correct that the example exhibits a number of race conditions. The fact that changing the order of process creation in the constructor affects the module's behavior, is evidence of that.

It's not a great example. No design should feature race conditions such as that.

DarrylLawson
  • 732
  • 3
  • 9