coroutines, how to ... ?

View: New views
3 Messages — Rating Filter:   Alert me  

coroutines, how to ... ?

by Milos Negovanovic :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

I am playing with coroutines and Ive came up with this simple example.
It does work but there is a small problem with it ... while running CPU
usage is constantly at 100%! Anyone might know what am I doing wrong?


test1 := Object clone do(
    run := method(
        loop(
            wait(5)
            "5" println
        )
    )
)

test2 := Object clone do(
    run := method(
        loop(
            wait(1)
            "1" println
        )
    )
)

server := Socket Server clone
server setHost("192.168.2.2")
server setPort(9000)

test1 @@run
test2 @@run
server start


Regards
--
Milos Negovanovic
milos.negovanovic@...

Re: coroutines, how to ... ?

by Steve Dekorte :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


I'm guessing the wait() may be a busy wait and you may need to set the  
EventManager timeout:

EventManager setListenTimeout(timeout)

to something reasonable.


On 2009-07-20, at 11:48 AM, Milos Negovanovic wrote:

> Hi,
>
> I am playing with coroutines and Ive came up with this simple example.
> It does work but there is a small problem with it ... while running  
> CPU
> usage is constantly at 100%! Anyone might know what am I doing wrong?
>
>
> test1 := Object clone do(
>    run := method(
>        loop(
>            wait(5)
>            "5" println
>        )
>    )
> )
>
> test2 := Object clone do(
>    run := method(
>        loop(
>            wait(1)
>            "1" println
>        )
>    )
> )
>
> server := Socket Server clone
> server setHost("192.168.2.2")
> server setPort(9000)
>
> test1 @@run
> test2 @@run
> server start
>
>
> Regards
> --
> Milos Negovanovic
> milos.negovanovic@...
>
>
> ------------------------------------
>
> Yahoo! Groups Links
>
>
>
>


Re: coroutines, how to ... ?

by Steve Dekorte :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


FTM, use a EventManager timeout instead of wait() for non-busy waits.