resource user() import bounded_buffer var pnap : int := 3, cnap : int := 3 var run_time : int := 60 getarg(2, pnap) # buffer size is argument 1 and getarg(3, cnap) # is getarg-ed in the monitor! getarg(4, run_time) writes("main user resource alive, pnap = ", pnap, ", cnap = ", cnap, ", and run_time = ", run_time, "\n") process producer var it : real var napping : int do true -> it := random() writes("age=", age(), ", PRODUCER produced item ", it, "\n") bounded_buffer.deposit(it) napping := int(random(1000*pnap)) writes("age=", age(), ", PRODUCER deposited item ", it, " and napping for ", napping, "ms\n") nap(napping) od end producer process consumer var it : real var napping : int do true -> writes("age=", age(), ", consumer wants to consume ...\n") it := bounded_buffer.fetch() napping := int(random(1000*cnap)) writes("age=", age(), ", consumer fetched item ", it, " and napping for ", napping, "ms\n") nap(napping) od end consumer nap(1000*run_time); write("must stop now"); stop end user /* ............... Example compile and run(s) % m2sr -sx bb.m % sr -o bb bb.sr driver.sr bb.sr: driver.sr: bb.sr: driver.sr: linking: % ./bb 5 1 3 7 bounded buffer alive with 5 slots main user resource alive, pnap = 1, cnap = 3, and run_time = 7 age=46, PRODUCER produced item 0.606729 age=55, consumer wants to consume ... **** Printing for not_full **** 0 waiting process(es) **** Printing for not_empty **** 0 waiting process(es) there are now 1 items in the buffer no consumers are waiting age=79, PRODUCER deposited item 0.606729 and napping for 876ms **** Printing for not_full **** 0 waiting process(es) **** Printing for not_empty **** 0 waiting process(es) there are now 0 items in the buffer no producers are waiting age=114, consumer fetched item 0.606729 and napping for 2825ms age=974, PRODUCER produced item 0.270639 **** Printing for not_full **** 0 waiting process(es) **** Printing for not_empty **** 0 waiting process(es) there are now 1 items in the buffer no consumers are waiting age=1093, PRODUCER deposited item 0.270639 and napping for 412ms age=1514, PRODUCER produced item 0.490240 **** Printing for not_full **** 0 waiting process(es) **** Printing for not_empty **** 0 waiting process(es) there are now 2 items in the buffer no consumers are waiting age=1539, PRODUCER deposited item 0.490240 and napping for 92ms age=1644, PRODUCER produced item 0.679252 **** Printing for not_full **** 0 waiting process(es) **** Printing for not_empty **** 0 waiting process(es) there are now 3 items in the buffer no consumers are waiting age=1669, PRODUCER deposited item 0.679252 and napping for 179ms age=1854, PRODUCER produced item 0.163522 **** Printing for not_full **** 0 waiting process(es) **** Printing for not_empty **** 0 waiting process(es) there are now 4 items in the buffer no consumers are waiting age=1879, PRODUCER deposited item 0.163522 and napping for 837ms age=2724, PRODUCER produced item 0.407361 **** Printing for not_full **** 0 waiting process(es) **** Printing for not_empty **** 0 waiting process(es) there are now 5 items in the buffer no consumers are waiting age=2749, PRODUCER deposited item 0.407361 and napping for 837ms age=2944, consumer wants to consume ... **** Printing for not_full **** 0 waiting process(es) **** Printing for not_empty **** 0 waiting process(es) there are now 4 items in the buffer no producers are waiting age=2956, consumer fetched item 0.270639 and napping for 1154ms age=3594, PRODUCER produced item 0.123102 **** Printing for not_full **** 0 waiting process(es) **** Printing for not_empty **** 0 waiting process(es) there are now 5 items in the buffer no consumers are waiting age=3625, PRODUCER deposited item 0.123102 and napping for 417ms age=4054, PRODUCER produced item 0.734775 **** Printing for not_full **** 0 waiting process(es) **** Printing for not_empty **** 0 waiting process(es) age=4114, consumer wants to consume ... **** Printing for not_full **** 1 waiting process(es), all with rank 0 **** Printing for not_empty **** 0 waiting process(es) there are now 4 items in the buffer producers are waiting age=4126, consumer fetched item 0.490240 and napping for 1063ms **** Printing for not_full **** 0 waiting process(es) **** Printing for not_empty **** 0 waiting process(es) there are now 5 items in the buffer no consumers are waiting age=4136, PRODUCER deposited item 0.734775 and napping for 360ms age=4504, PRODUCER produced item 0.806480 **** Printing for not_full **** 0 waiting process(es) **** Printing for not_empty **** 0 waiting process(es) age=5194, consumer wants to consume ... **** Printing for not_full **** 1 waiting process(es), all with rank 0 **** Printing for not_empty **** 0 waiting process(es) there are now 4 items in the buffer producers are waiting age=5207, consumer fetched item 0.679252 and napping for 1546ms **** Printing for not_full **** 0 waiting process(es) **** Printing for not_empty **** 0 waiting process(es) there are now 5 items in the buffer no consumers are waiting age=5217, PRODUCER deposited item 0.806480 and napping for 987ms age=6214, PRODUCER produced item 0.679876 **** Printing for not_full **** 0 waiting process(es) **** Printing for not_empty **** 0 waiting process(es) age=6764, consumer wants to consume ... **** Printing for not_full **** 1 waiting process(es), all with rank 0 **** Printing for not_empty **** 0 waiting process(es) there are now 4 items in the buffer producers are waiting age=6787, consumer fetched item 0.163522 and napping for 570ms **** Printing for not_full **** 0 waiting process(es) **** Printing for not_empty **** 0 waiting process(es) there are now 5 items in the buffer no consumers are waiting age=6799, PRODUCER deposited item 0.679876 and napping for 657ms must stop now % ./bb 5 3 1 7 bounded buffer alive with 5 slots main user resource alive, pnap = 3, cnap = 1, and run_time = 7 age=50, PRODUCER produced item 0.964400 age=59, consumer wants to consume ... **** Printing for not_full **** 0 waiting process(es) **** Printing for not_empty **** 0 waiting process(es) there are now 1 items in the buffer no consumers are waiting age=143, PRODUCER deposited item 0.964400 and napping for 2893ms **** Printing for not_full **** 0 waiting process(es) **** Printing for not_empty **** 0 waiting process(es) there are now 0 items in the buffer no producers are waiting age=236, consumer fetched item 0.964400 and napping for 764ms age=1027, consumer wants to consume ... **** Printing for not_full **** 0 waiting process(es) **** Printing for not_empty **** 0 waiting process(es) age=3057, PRODUCER produced item 0.472359 **** Printing for not_full **** 0 waiting process(es) **** Printing for not_empty **** 1 waiting process(es), all with rank 0 there are now 1 items in the buffer consumers are waiting age=3089, PRODUCER deposited item 0.472359 and napping for 2311ms **** Printing for not_full **** 0 waiting process(es) **** Printing for not_empty **** 0 waiting process(es) there are now 0 items in the buffer no producers are waiting age=3099, consumer fetched item 0.472359 and napping for 902ms age=4007, consumer wants to consume ... **** Printing for not_full **** 0 waiting process(es) **** Printing for not_empty **** 0 waiting process(es) age=5407, PRODUCER produced item 0.270513 **** Printing for not_full **** 0 waiting process(es) **** Printing for not_empty **** 1 waiting process(es), all with rank 0 there are now 1 items in the buffer consumers are waiting age=5434, PRODUCER deposited item 0.270513 and napping for 1533ms **** Printing for not_full **** 0 waiting process(es) **** Printing for not_empty **** 0 waiting process(es) there are now 0 items in the buffer no producers are waiting age=5489, consumer fetched item 0.270513 and napping for 754ms age=6257, consumer wants to consume ... **** Printing for not_full **** 0 waiting process(es) **** Printing for not_empty **** 0 waiting process(es) age=6979, PRODUCER produced item 0.00863305 **** Printing for not_full **** 0 waiting process(es) **** Printing for not_empty **** 1 waiting process(es), all with rank 0 there are now 1 items in the buffer consumers are waiting must stop now */