#19MediumThread Synchronization· Semaphores and Turn Taking
Print FooBar Alternately
Input format
n: number of foo/bar pairs to print
Output format
String: "foobar" repeated n times
Examples
Input: n = 1
Output: foobar
One foo followed by one bar.
Input: n = 2
Output: foobarfoobar
The threads alternate: foo, bar, foo, bar.
Constraints
- 1 <= n <= 1000
Study first
- #concurrency
- #threads
- #semaphores
- #synchronization
