issue-#156 adding Coroutines to BlackBox

Merged to the master branch
Post Reply
User avatar
Josef Templ
Posts: 2047
Joined: Tue Sep 17, 2013 6:50 am

issue-#156 adding Coroutines to BlackBox

Post by Josef Templ »

I would like to propose "adding Coroutines to BlackBox.
Coroutines are not as powerful as threads but they are much simpler
and somewhere in between classical BlackBox and a multi-threaded system.

For the issue see https://redmine.blackboxframework.org/issues/156.

For the proposed solution see https://redmine.blackboxframework.org/p ... 97faa7e691.

The solution is based on Windows fibers (inspired by the CPC package Co_). Fibers are just another name for coroutines.
The main work is in the integration into Kernel services such as garbage collection, trap handling and trap cleaners.
Fortunately, most things worked almost unchanged.

The proposed solution does not make any modifications to Kernel unless Coroutines are really used.
This should help in avoiding any instabilities. The Kernel modifications are encapsulated in a set of auxiliary procedures,
which avoids exporting low-level Kernel data structures. One WinApi function was missing and has been added.

A test version is here: http://blackboxframework.org/unstable/i ... a1.816.zip.

A test program can be found below.

- Josef

StdCoder.Decode ..,, ..2a....3Qw7uP5PRPPNR9Rbf9b8R79FTvMf1GomCrlAy2xhX,Cb2x
hXhC6FU1xhiZiVBhihgmRiioedhgrZcZRiXFfaqmSrtuGfa4700zdGrr8rmCLLCJuyKtYcZRiX
7.2.s,M0H.0k,5TWyql.bnayKmKKqGomC5XzET1.PuP.MHT9N9ntumaU2,CJuyKtQC98P9PP7O
NbXmb.2.we6k20.T802U.U08J99SdfJHPNjvQCJuGKfaqmY6MwdONl1QCh0708T,U..w.Az5U.
2U18J99SqorGqmQCbWBxhYFWUl1UnNHEWUmr.6.QU4k5kxL.0E.Ed4.86.QC18RdfQHfMf9R9v
Q7ONb17.,.D,,6.I16.M.6.JFyuv.U.2m,.3R.AU0KyB.,U0,,UO.,.1.e0E.2UwK.616.7T.A
UG.J20.Cp69UPoZ0cUXDF9fR5uPPPP1fP7PNZvQRtIdHf.2UlbcZpC.c9h0E.8z,U.EEE.E1U.
M3656.kd.cwR.0.,,,.B.0UJUX.,.b0.U...B.0UJUjUzjdDZcJZd33Y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WGhigFWE.4Te.sQRdIf9P9HWE.8z,E.0.L3D.53,6.C6.Qii
Q8CJuaLqKKWKqtCK.4D.o3aLq.,cwD.0.E2EhU.E,,.RNEd1U2ll0U2U...G00k.0U.6.665hK
E.mLT5UTyB4.4.0E.cUZT1E..UO.,.1.e06.2UEC.6..mEw71suHz9KNPvZ0CSTXhhAsET1.UG
6.2..606.k22.0sfCbgAYX8Utj00MyfU.Qfc7f77a.br,...
--- end of encoding ---

moderated 29.03.2017 (fix encoded example)
Ivan Denisov
Posts: 1700
Joined: Tue Sep 17, 2013 12:21 am
Location: Russia

Re: issue-#156 adding Coroutines to BlackBox

Post by Ivan Denisov »

Such topic should be discussed carefully. Some abstract interface and the realisation for Windows can be designed. However this form of realization unacceptable.

There should not be modules importing WinApi in the System folder. Your design is binding BlackBox to Windows OS forever. Unfortunately you did not here any arguments in previous discussion. I see that you did not get the idea of cross-platform BlackBox. I will try to explain again, however I have not much time now to write very long posts.
User avatar
Robert
Posts: 1024
Joined: Sat Sep 28, 2013 11:04 am
Location: Edinburgh, Scotland

Re: issue-#156 adding Coroutines to BlackBox

Post by Robert »

Is this proposed capability similar to the Modula-2 capability?
User avatar
DGDanforth
Posts: 1061
Joined: Tue Sep 17, 2013 1:16 am
Location: Palo Alto, California, USA
Contact:

Re: issue-#156 adding Coroutines to BlackBox

Post by DGDanforth »

Ivan Denisov wrote: There should not be modules importing WinApi in the System folder.
I agree with Ivan on this point.

I do like the idea of Coroutines.

-Doug
luowy
Posts: 234
Joined: Mon Oct 20, 2014 12:52 pm

Re: issue-#156 adding Coroutines to BlackBox

Post by luowy »

Great! a big step close to golang, more feature more easy to port go package to oberon.
it is definitely worth to add,IMO.
User avatar
DGDanforth
Posts: 1061
Joined: Tue Sep 17, 2013 1:16 am
Location: Palo Alto, California, USA
Contact:

Re: issue-#156 adding Coroutines to BlackBox

Post by DGDanforth »

Josef,
I get a "checksum error!" when I try to decode you code.

-Doug
User avatar
Josef Templ
Posts: 2047
Joined: Tue Sep 17, 2013 6:50 am

Re: issue-#156 adding Coroutines to BlackBox

Post by Josef Templ »

the test program again...

StdCoder.Decode ..,, ..2a....3Qw7uP5PRPPNR9Rbf9b8R79FTvMf1GomCrlAy2xhX,Cb2x
hXhC6FU1xhiZiVBhihgmRiioedhgrZcZRiXFfaqmSrtuGfa4700zdGrr8rmCLLCJuyKtYcZRiX
7.2.s,M0H.0k,5TWyql.bnayKmKKqGomC5XzET1.PuP.MHT9N9ntumaU2,CJuyKtQC98P9PP7O
NbXmb.2.we6k20.T802U.U08J99SdfJHPNjvQCJuGKfaqmY6MwdONl1QCh0708T,U..w.Az5U.
2U18J99SqorGqmQCbWBxhYFWUl1UnNHEWUmr.6.QU4k5kxL.0E.Ed4.86.QC18RdfQHfMf9R9v
Q7ONb17.,.D,,6.I16.M.6.JFyuv.U.2m,.3R.AU0KyB.,U0,,UO.,.1.e0E.2UwK.616.7T.A
UG.J20.Cp69UPoZ0cUXDF9fR5uPPPP1fP7PNZvQRtIdHf.2UlbcZpC.c9h0E.8z,U.EEE.E1U.
M3656.kd.cwR.0.,,,.B.0UJUX.,.b0.U...B.0UJUjUzjdDZcJZd33YIhgnZi1xhmxhpZidph
ZRivgVBAdB3eDJeI3Y1xhm,69,7HTvNrN1P6Jn8I9O1HMGdPNZPMdvPZ96v76VuHHeHdOFZ86d
uH,dI9uETeI786FtETfQ.umVyKty4M8PM0H6Sp76HeHdOFDOFZO1HMFR8FrN1HM1HcE1vMLvNZ
vPffP79J1vQL96v76V0I8..Eukt.Ud2Y3pd2R5P6IZuH5OF7OJZOF,78d9OHvQp76H8R9fQkI0
GdKLrin4aEf4Id0moeHEaIbsFQbBIc3xc7pdBAVAxhbpZHZimBhixgcIY0hc5B7,NGd1c6HtC,
7HTvNR7HRvCPM0BuHZ86H96pND,7A,7JT86n767uHPM0H6RFPObf9l96pND,NOrN1HM05uPZvP
Un7JZPMRvQBPNZ98d9OHXaJijhhdgV7gcCV7Ydjld.gcCZcUAdohA..N09eH786ZORRXB28.0G
eK4H8R91IZvgV7o86Rp76H8R.rN1UBcH9uJFNOdP8rN1Cor.kYuqoGLIaKua0..d0UdZidUL3d
7Zd33YdZiiQioBgohgUgbUQcjJC.CruCLsKKrGqmGKEGobq.NuPQ8.l96vd6HtC,,aIrGLIaKu
uGwamR0GaEak2akV.UI,.kWuYBgcCZcUYeZ7R.k4.Uc.pFV4qli4oBd0H76ZORM0h0e1.I6UAV
H,cE90,dE11.c6HtC,,m2o6.01.6HsI.W5.A7M8r76N0N0akVsPG56I1PRKKI4HM0HMam4akWs
C.b0kWu23OM51oB..N09WUI8M1.66d03OM51.IZvgV7o8IgoJbUIcV,.QbBIc3VBcHcMdP8rN1
C2YCkYAB8Kua0..d0UWZidkWu2d0.oB.PMFR8FU1,d1gVBIUIhgnZC.EeKqtA7.Pc.dONQ6..8
2Ui,qk48EWKKvGom8quSKLKJrmqr4KmGJoaqt0GeKqtQ66REECor85.PcUXDJ99SCoruKu8rrm
KqKKtCLLCZYRcoJigZcZRiX3Ulb8..umVyKrG5EWKqtCK.Q6AA.cQ...sQR,.G20EtH.0.G,0.
aU.6.,..1cUXDJcIf9P9fQbf9bWGhigFWE.4Te.sQRdIf9P9HWE.8z,E.0.L3D.53,6.C6.Qii
Q8CJuaLqKKWKqtCK.4D.o3aLq.,cwD.0.E2EhU.E,,.RNEd1U2ll0U2U...G00k.0U.6.665hK
E.mLT5UTyB4.4.0E.cUZT1E..UO.,.1.e06.2UEC.6..mEw71suHz9KNPvZ0CSTXhhAsET1.UG
6.2..606.k22.0sfCbgAYX8Utj00MyfU.Qfc7f77a.br,...
--- end of encoding ---

- Josef
User avatar
Josef Templ
Posts: 2047
Joined: Tue Sep 17, 2013 6:50 am

Re: issue-#156 adding Coroutines to BlackBox

Post by Josef Templ »

Robert wrote:Is this proposed capability similar to the Modula-2 capability?
Yes, but ..
- without any interrupt features, i.e. binding coroutines to interrupts
- my Coroutines are expressed as objects, which is quite natural, I think,
if you have OO features in the language. Behavior and state visible to other coroutines
is kept together in the extended record. No need for additional global variables, type casts etc.
One 'target' parameter for Transfer is then sufficient.

- Josef
Last edited by Josef Templ on Wed Mar 22, 2017 10:29 am, edited 1 time in total.
User avatar
Josef Templ
Posts: 2047
Joined: Tue Sep 17, 2013 6:50 am

Re: issue-#156 adding Coroutines to BlackBox

Post by Josef Templ »

luowy wrote:Great! a big step close to golang, more feature more easy to port go package to oberon.
it is definitely worth to add,IMO.
luowy, are you familiar with go-routines?

What concerns me is the question if it should be allowed to RETURN from a coroutine
and, if yes, what happens then. The current implementation returns to the 'caller', i.e. the
last coroutine that transferred control to the returning coroutine.
In Modula-2, if I remember correctly, this was not allowed at all.
A coroutine had to transfer control to another coroutine at the end or put a
LOOP ... END around the implementation.

How is this in GO?
As far as I have read go routines are multi-plexed on one or more OS threads.
So this seems to be a little different from plain old coroutines, which use a single thread only.
RETURN seems to be allowed at the end of a go routine. Right?

- Josef
Ivan Denisov
Posts: 1700
Joined: Tue Sep 17, 2013 12:21 am
Location: Russia

Re: issue-#156 adding Coroutines to BlackBox

Post by Ivan Denisov »

I analyzed the proposed solution. It is not hard to split this well. I will try to work this evening on this and suggest some version with a same interface.
Post Reply