Rendezvous: Difference between revisions
Content added Content deleted
(Go solution) |
(→{{header|Go}}: updated to use new WaitGroup feature. also improved exception message.) |
||
Line 230: | Line 230: | ||
"fmt" |
"fmt" |
||
"strings" |
"strings" |
||
"sync" |
|||
) |
) |
||
Line 249: | Line 250: | ||
reservePrinter := startMonitor(newPrinter(5), nil) |
reservePrinter := startMonitor(newPrinter(5), nil) |
||
mainPrinter := startMonitor(newPrinter(5), reservePrinter) |
mainPrinter := startMonitor(newPrinter(5), reservePrinter) |
||
var busy sync.WaitGroup |
|||
busy.Add(2) |
|||
⚫ | |||
mgDone := make(chan int) |
|||
go writer(mainPrinter, |
go writer(mainPrinter, "mg", mgText, &busy) |
||
busy.Wait() |
|||
⚫ | |||
<-hdDone |
|||
<-mgDone |
|||
} |
} |
||
Line 303: | Line 302: | ||
} |
} |
||
func writer(printer *rSync, text string, |
func writer(printer *rSync, id, text string, busy *sync.WaitGroup) { |
||
for _, line := range strings.Split(text, "\n", -1) { |
for _, line := range strings.Split(text, "\n", -1) { |
||
if e := printer.rendezvous(line); e != nil { |
if e := printer.rendezvous(line); e != nil { |
||
fmt.Println("**** |
fmt.Println("**** print job", id, "terminated:", e, "****") |
||
break |
break |
||
} |
} |
||
} |
} |
||
busy.Done() |
|||
}</lang> |
}</lang> |
||
Output: |
Output: |
||
<pre> |
<pre> |
||
Old Mother Goose, |
|||
Humpty Dumpty sat on a wall. |
Humpty Dumpty sat on a wall. |
||
Humpty Dumpty had a great fall. |
Humpty Dumpty had a great fall. |
||
Line 323: | Line 323: | ||
Jack's mother came in, |
Jack's mother came in, |
||
And caught the goose soon, |
And caught the goose soon, |
||
**** |
**** print job mg terminated: out of ink **** |
||
</pre> |
|||
=={{header|Oz}}== |
=={{header|Oz}}== |