Example 12.10. Example of a Rexx Readers and Writers
::method init expose readers writers readers = 0 writers = 0 ::method read unguarded /* Read if no one is writing */ expose writers readers guard on when writers = 0 readers = readers + 1 guard off /* Read the data */ say "Reading (writers:" writers", readers:" readers")." guard on readers = readers - 1 ::method write unguarded /* Write if no-one is writing or reading */ expose writers readers guard on when writers + readers = 0 writers = writers + 1 /* Write the data */ say "Writing (writers:" writers", readers:" readers")." writers = writers - 1