"Fossies" - the Fresh Open Source Software Archive

Member "ponyc-0.33.0/minimal-cases/issue-647/647.pony" (1 Nov 2019, 1088 Bytes) of package /linux/misc/ponyc-0.33.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Pony source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 """
    2 Causes uncontrolled memory usage with 4 threads
    3 """
    4 use "collections"
    5 
    6 actor Ping
    7   var _passes: U32
    8   var _total_passes: U32 = 0
    9 
   10   new create(passes: U32) =>
   11     _passes = passes
   12 
   13   be ping(partner: Pong) =>
   14     if (_total_passes < _passes) then
   15       partner.pong(this)
   16     end
   17     _total_passes = _total_passes + 1
   18 
   19 actor Pong
   20   be pong(partner: Ping) =>
   21     partner.ping(this)
   22 
   23 
   24 actor Main
   25   var _env: Env
   26   var _size: U32 = 3
   27   var _pass: U32 = 0
   28   var _pongs: U64 = 0
   29 
   30   new create(env: Env) =>
   31     _env = env
   32 
   33     try
   34       parse_args()
   35       start_messaging()
   36     else
   37       usage()
   38     end
   39 
   40   be pong() =>
   41     _pongs = _pongs + 1
   42 
   43   fun ref start_messaging() =>
   44     for i in Range[U32](0, _size) do
   45       let ping = Ping(_pass)
   46       let pong' = Pong
   47       ping.ping(pong')
   48     end
   49 
   50   fun ref parse_args() ? =>
   51     _size = _env.args(1).u32()
   52     _pass = _env.args(2).u32()
   53 
   54   fun ref usage() =>
   55     _env.out.print(
   56       """
   57       mailbox OPTIONS
   58         N   number of sending actors
   59         M   number of messages to pass from each sender to the receiver
   60       """
   61       )