Click here to Skip to main content
15,893,508 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am trying to understand concurrency concepts in this program. I am trying to understand it but I am not able to understand the main logic. I am not sure what signal and wait are actually doing here.

the core logic is here
export operation Hi
			if ! flip then
				stdout.putstring["Waiting Hi\n"]
				wait c
			end if
			stdout.putstring["Hi\n"]
			flip <- false
			signal c
		end hi
		export operation Ho
			if flip then
				stdout.putstring["Waiting Ho\n"]
				wait c
			end if
			stdout.putstring["Ho\n"]
			flip <- true
			signal c
		end ho


What I have tried:

The output is
Hi
Waiting Hi
Ho
Hi
Ho
Hi
Ho
Hi
Ho
Hi
Ho
Hi
Ho
Waiting Ho
Hi
Ho
Hi
Ho
Hi
Ho
Hi
Ho


Can anyone explain how this output is generated how signal and wait are executing the output
Posted
Updated 23-Feb-17 6:42am
Comments
Jochen Arndt 23-Feb-17 9:01am    
This looks like Emerald.
I think there are not so many (if any) here knowing that language (I don't).

As a first step I suggest to lookup the documentation for the wait and signal functions.
[no name] 23-Feb-17 9:05am    
I can't tell you what it is either. Never saw it before. I can tell that it is not C.
Albert Holguin 23-Feb-17 12:01pm    
That's definitely not C. If you need help with whatever language this is, tag appropriately. If you just want help with understanding concurrency in general, don't use a language specific tag.

1 solution

No idea what that language is, but it is not C. It looks to me like there are two independent activities, hi and ho. Each one tests a flag and either waits, or continues processing. The waiting activity does nothing until the other activity sends a signal which restarts it. They then continue on opposite tracks. The output shows the order of execution,
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900