A question for semaphore channel in SystemC

Status
Not open for further replies.

william_luo

Junior Member level 2
Joined
Mar 25, 2013
Messages
23
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,283
Visit site
Activity points
1,465
Hi everyone,

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

I found an example of semaphore channel on asic world (https://www.asic-world.com/systemc/channels3.html) but have a little confused about it. This example provides 3 process (SC_CTHREAD): bus_semaphore(), do_read() and do_write(). I have a concurrency question about the former two.

At the first 1ns for this example, the first process bus_semaphore() works and can print out two lines like "@1 ns ....". At the same time in this thread then, the semaphore value (bus) changes into 2 (bus.post()). Then this thread will 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 expression 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? I am stuck at this point for a long time. Can anyone help me?

Thanks in advance!
Wayne
 

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.
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…