Re: Howto use pause and resume with latest IO

petri rokka <[email protected]>
Newsgroups gmane.comp.lang.io
Message-ID <[email protected]>
2011/5/23 Jan-Paul Bultmann <[email protected]>

>
>
>
> Hey MailingList, is there a Turorial on embedding Io?
>
>
> On May 23, 2011, at 3:01 PM, petri rokka wrote:
>
>
>
> I fail to see why application should always exit when yieldingCoros
> empties. It is a normal state because yieldingCoros is empty when i start io
> interpreter.
>
> Yes, but then there is already a Coroutine running. When you yield a
> coroutine you will append the one to yield to yieldingCoros, then remove the
> first in yieldingCoros and start it by calling resume on it.
> You see it may happen that yieldingCoros is empty, in this case the
> currently running coro will simply continue. But notice, at no point the
> coroutine that yields is stopped! This is all done by the resuming
> coroutine. This also means that there can never be more than one coroutine
> running at once because the newly started will always replace the running.
> And there can never be zero coroutines running (what would you replace the
> currently running with?).
> This is because coroutines are not about starting and stopping
> calculations, there are about context switching at the right time.
>

But there can be zero coroutines yielding. :) And that is what i want to
have by pausing the last yielding coro.

>
> I need to pause the last coro to give back control to the C++ app that
> called the io evaluation function. Io is running in a separate thread in the
> C++ app, but it needs to do c++ stuff to communicate with other threads.
>
> when you call doFile/String/Whatever out of your c++ code it should return
> there once the handling is done. I think.
>

Yes it does. But i have to have zero yielding coros.. :)


>
> I made overloaded implementation of pause that does not exit when
> yieldingCoros empties and it seems to work fine.
>
> Wanna see code^^, I suposse the coroutine of you simply continues to run,
> finishes its work and then exits.
>
>
I simply removed the exit


Coroutine do(
    pause := method(
        yieldingCoros remove(self)
        if(isCurrent,
            next := yieldingCoros removeFirst
            if(next,
                next resume
            )
        ,
            yieldingCoros remove(self)
        )
    )
)


>
> How can i get the currentCoro If I try-catch exception inside actor method.
>
> actor doSomething := method(
>     e := try(
>                 actor realCoro := ????
>         doFile("test_that_yields_many_times.io")
>     )
> )
>
> You could do the workaround from steve. Before pausing it you could save
> the currentCoroutine into a slot.
>

I can do that.. but does "actor pause" work after that try block?


>
> Cheers Jan
>
>
> ...
> actor doSomething
> ...
> actor pause
> ...
> actor realCoro resume
> ...
>
>
>
> 2011/5/23 Jan-Paul Bultmann <[email protected]>
>
>>
>>
>>
>> On May 18, 2011, at 3:58 PM, petri rokka wrote:
>>
>>
>>
>> Great that you found a fix :) . Can you post the fix here so i can try it
>> out. Should my posted test app work with it?
>>
>> Btw. I am also having problem with pause. I need to pause/resume  the only
>> existing coro in application to pause it and continue it later (io is
>> embedded in my c++ app) , but its impossible because pause forces
>> application system exit at that point. :/
>>
>> Could you make different pause that doesn't force the system exit?
>>
>>
>> Hey sorry I write that late, but I was on the Typo Berlin, so not much net
>> and even less time.
>>
>> I don't think that what you want to do is possible with coroutines.
>> The reason is that when pause is called, the coroutine wont actually
>> pause. Instead another coroutine will resume, taking care of replacing and
>> thus stopping the currently running.
>> I would instead recommend to run the embedded VM in it's own thread and
>> pause it externally, or use the thread Addon, though I don't know how to use
>> that.
>>
>> Hope it helps.
>> Cheers Jan
>>
>> 2011/5/17 Jan-Paul Bultmann <[email protected]>
>>
>>>
>>>
>>>
>>> On May 17, 2011, at 8:50 PM, Steve Dekorte wrote:
>>>
>>>
>>>
>>>
>>> On 2011-05-17 Tue, at 06:34 AM, Jan-Paul Bultmann wrote:
>>> > Why is a new coroutine generated anyways? And especially where? I would
>>> consider it unwanted behavior if you resume one Coroutine but your stuff
>>> will run in another.
>>>
>>> There are a few cases:
>>> 1) when you do a try() - exceptions handling is implemented with coros.
>>> 2) when a coro gets close to running out of stack space, it creates a new
>>> coro to continue executing in.
>>>
>>> Cool to know, thanks :)
>>>
>>>
>>> It's surprising this hasn't come up before, but your code exposes a bug
>>> in the current actor implementation. I'll add a bit of code to Coroutine to
>>> make sure resumes are sent to the proper child coroutine.
>>>
>>> - Steve
>>>
>>>
>>>
>>>
>>
>>
>>
>>
>
>
>  
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.