Walter: any plan to add support for yield/return Iterators/generators?

Mikola Lysenko mclysenk at mtu.edu
Tue Sep 5 16:40:31 PDT 2006


Marcio wrote:
>     Neat, thanks. I had seen your post before already. But I want to 
> leverage multi core etc. CCR actually does this really well. Also, the 
> yield return in generators are not the same as the yield in coroutines. 
> They are much higher level to the end user.
> 
>     Also: do you use a stack or the heap? It was not clear from the FAQ, 
> although the delegate example suggests you rely on 1 thread and 
> therefore its stack. One of the problems with threads is that you pay 
> the price of a stack in advance, instead of as you go (N threads means N 
> stacks sparsely used). Contrast this with Stackless Python for example, 
> which uses continuation passing & the heap. If I understood your FAQ, 
> you use 1 Thread so just 1 stack, but on the other hand you can't 
> leverage multi core because of that.
> 
> marcio
> 

I believe there is a misunderstanding.  The objective of StackThreads is 
to give a program more than one stack - for exactly the reasons you have 
listed.

All stack memory is heap allocated inside the StackContext.  As you 
create contexts, you will allocate more stacks.  Each context can be 
considered a continuation.  Daniel Keep has already demonstrated a 
coroutine/generator system based on the library which is included with 
version 0.2.

At the moment it is single threaded because D lacks a decent thread 
local storage mechanism.  It would be trivial to make the implementation 
thread safe if it is ever added.  (Only 2 lines of code would need to 
change.)  One work around would be to integrate the StackContext object 
with std.thread by adding the necessary members to Phobos' Thread 
object, but this is strictly DIY.



More information about the Digitalmars-d mailing list