Download pseudo source code

procedure main(argc, argv[]):
  if argc = 7 then
    shared buffer_capacity := integer(argv[1])
    shared buffer as array of buffer_capacity of float
    shared rounds := integer(argv[2])
    shared producer_min_delay := integer(argv[3])
    shared producer_max_delay := integer(argv[4])
    shared consumer_min_delay := integer(argv[5])
    shared consumer_max_delay := integer(argv[6])

    create_threads(1, produce)
    create_threads(1, consume)
  end if
end procedure

procedure produce:
  declare count := 0
  for round := 1 to rounds do
    for index := 0 to buffer_capacity do
      delay(random_between(producer_min_delay, producer_max_delay))
      buffer[index] := ++count
      print("Produced ", buffer[index])
    end for
  end for
end procedure

procedure consume:
  for round := 1 to rounds do
    for index := 0 to buffer_capacity do
      value := buffer[index]
      delay(random_between(consumer_min_delay, consumer_max_delay))
      print("Consumed ", value)
    end for
  end for
end procedure

function random_between(min, max):
  return min + rand() % (max - min)
end function