Feature #156

adding Coroutines to BlackBox

Added by J. Templ over 2 years ago. Updated over 2 years ago.

Status:ClosedStart date:03/21/2017
Priority:NormalDue date:
Assignee:J. Templ% Done:

0%

Category:-
Target version:1.7.1
Forum topic:

Description

It is proposed to add Coroutines to BlackBox. Even if coroutines are not as powerful as threads, they can for example simplify writing of long-running background tasks considerably.
A first inspiration can be found in the CPC package named 'Co_' by Dmitry V.Dagaev, 2014-03-28. This package is based on Windows fibers. It has, however, a rather complex programming interface and is not integrated with the garbage collector and other Kernel services.

Proposed by J. Templ, 2017-03-21.

Associated revisions

Revision 94253d45
Added by J. Templ over 2 years ago

ObxCoroutines added. Refs: #156.
Build-Tool extended for coroutines.

Signed-off-by: Josef Templ <>

Revision 5ce6ea8c
Added by J. Templ over 2 years ago

source code indentation fixed. Refs: #156.

Revision 69c1383c
Added by J. Templ over 2 years ago

the classical SameFringe example added. Refs: #156.

Revision 5f9299cb
Added by J. Templ over 2 years ago

trap cleaners called when deleting a coroutine stack. Refs: #156.

Signed-off-by: Josef Templ <>

Revision fc2ccc19
Added by J. Templ over 2 years ago

field 'parent' added and patterns 'Iterator' and 'Task' introduced. Refs: #156.
from renamed to source.
Pause renamed to Sleep.
RETURN now transfers to parent.
Usage of 'Transfer' is not required for special patterns Iterator and Task.

Signed-off-by: Josef Templ <>

Revision f6941faf
Added by J. Templ over 2 years ago

Coroutines.SetStackSize added. Refs: #156.
plus a bug fix in the Kernel's garbage collection strategy.
Coroutine stacks must only be marked if the coroutine is referenced.
Otherwise an unterminated but unreferenced coroutine survives forever.

Signed-off-by: Josef Templ <>

Revision 2a2351a9
Added by I. Denisov over 2 years ago

Realisation was moved to Host subsystem, Kernel cleaned from WinApi calls. Task pattern removed. That is the draft version. Refs: #156.

Revision 5e03da1b
Added by I. Denisov over 2 years ago

Add Coroutines and HostCoroutines to build lists. Refs: #156.

Revision 2b47c718
Added by I. Denisov over 2 years ago

Troubles with BlackBox termination (sigfault). Remove HostCoroutines from HostDialog to make test build. Refs: #156.

Revision 402be289
Added by I. Denisov over 2 years ago

Remove Coroutines and HostCoroutines from bbscript compile list. Refs: #156.

Revision f56119eb
Added by J. Templ over 2 years ago

Task.Sleep(0) optimized. Refs: #156.
A task using Sleep(0) runs as fast as possible but without blocking the user interface.
Prime number calculation used as example for background task.
Robustness of trap handling after exhausting the stack space improved.
Coroutines.Init now traps if a coroutine cannot be created.
Otherwise it is hard to see where the problem comes from.

Signed-off-by: Josef Templ <>

Revision 2315e8e8
Added by I. Denisov over 2 years ago

Windows Fibers realisation for Coroutines was moved from Kernel to HostCoroutines. Refs: #156.

Revision d2e29f07
Added by J. Templ over 2 years ago

handling of very small stack sizes improved. Refs: #156.

Signed-off-by: Josef Templ <>

Revision 20de70d1
Added by I. Denisov over 2 years ago

Handling of very small stack sizes improved. Refs: #156.

Revision 97d6cf15
Added by J. Templ over 2 years ago

stackBase reset in Kernel.AddCoroutines. Refs: #156.
This enables one to reuse the very same object after
RemoveCoroutine. This feature is used in the Co_ package.

Signed-off-by: Josef Templ <>

Revision 142efe73
Added by J. Templ over 2 years ago

bug fixed in Kernel.MarkReferencedCoroutines. Refs: #156.
Plus trapChecker cleared in RemoveCoroutine.

Signed-off-by: Josef Templ <>

Revision 8bc2f85b
Added by I. Denisov over 2 years ago

stackBase reset in Kernel.AddCoroutines.
This enables one to reuse the very same object after
RemoveCoroutine. This feature is used in the Co_ package.
bug fixed in Kernel.MarkReferencedCoroutines.
Plus trapChecker cleared in RemoveCoroutine.
Fixes done by Josef Templ. Signed-off-by: Ivan Denisov.
Refs: #156.

Revision 47cf17e6
Added by J. Templ over 2 years ago

support for multiple client modules added. Refs: #156.
This allows, for example, that modules Coroutines and Co_Routines
can both be used. The Kernel's coroutine support ends when both modules are unloaded,
i.e. EndCoroutines has been called twice after initCoroutines has been called twice.

Signed-off-by: Josef Templ <>

Revision ced262dc
Added by I. Denisov over 2 years ago

HostCoroutines load directly in Coroutines module. Refs: #156.

Revision 8cc1176a
Added by I. Denisov over 2 years ago

Code formatting improved. Refs: #156.

Revision 3d87c380
Added by J. Templ over 2 years ago

improved heuristics for Task.Sleep(0). Refs: #156.
CPU utilization is now close to 100% in both server mode and normal mode.

Signed-off-by: Josef Templ <>

Revision 4d9eefe3
Added by J. Templ over 2 years ago

Import of SYSTEM eliminated in Coroutines. Refs: #156.

Signed-off-by: Josef Templ <>

Revision ff2ab360
Added by J. Templ over 2 years ago

small optimization of Sleep(0). Refs: #156.
docu of Sleep(0) improved.

Signed-off-by: Josef Templ <>

Revision 0d53aded
Added by J. Templ over 2 years ago

Iterator.Generate renamed to Next. Refs: #156.
In addition call of Kernel.BeginCoroutines is delayed until the first Coroutines.Init,
i.e. it is no longer in the module body.

Signed-off-by: Josef Templ <>

History

#1 Updated by J. Templ over 2 years ago

  • Description updated (diff)

#2 Updated by J. Templ over 2 years ago

  • Status changed from New to Closed

Also available in: Atom PDF