www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Stack Threads and Exceptions

reply mclysenk mtu.edu writes:
I've been working on a StackThread library which allows users to create
unlimited lightweight threads which execute round robin style.  The basic idea
behind this is that many game actions like animations or menus use loops to
perform certain actions, like

void ai_update()
{
while(not_dead)
{
while(my_pos != player_pos)
{
move_toward(player_pos);
end_turn();
}

while(my_pos == player_pos)
{
attack_player()
end_turn();
}
}
}

This code can be replaced with the use of complicated finite state machines, but
the result is usually rather hideous.  Here's an example:

void ai_update()
{
switch(my_state)
{
case SEARCHING:
move_toward(player_pos);
if(my_pos == player_pos)
my_state = ATTACKING;
break;

case ATTACKING:
if(my_pos != player_pos)
{
my_state = SEARCHING;
break;
}
attack_player();
break;

case DEAD:
break;
}
}

Another option would be to give each object it's own thread, but this can make
the situation even worse especially with concurrency.  I expect that stack
threads will improve the readability of code and make it easier to generate
novell game logic.

Each stack thread has its own chunk of stack memory, and the stack threading
library just switches them round robin style until it returns to the main
program.  The main program must call run() once a frame to execute one time
slice for each of the stack threads, which have control of the cpu until they
yield it.  This is very fast and pretty simple to do, just a pushad/popad and a
modified esp. In addition, it also removes all possibility for race
conditions/deadlocks since none of the threads are actually running
concurrently.

Unfortunately, I've hit a snag.  The library in its current state is usable, the
threads can be run, suspended, resumed and killed, but there are no exceptions.
Are there any documents out there on how D's exceptions work or any other sorts
of info?  I tried sorting it out from the source in deh.c, but it's rather
complex.
Nov 29 2005
parent reply Sean Kelly <sean f4.ca> writes:
mclysenk mtu.edu wrote:
 I've been working on a StackThread library which allows users to create
 unlimited lightweight threads which execute round robin style.  The basic idea
 behind this is that many game actions like animations or menus use loops to
 perform certain actions
Interesting. You might be interested in a paper that was published recently on this entitled "User-Level Threads for Hierarchically Composed Simulations." If I remember correctly, it includes a link to a full implementation of the concept that's quite portable (though it is written in C++). Link is here: http://members.ozemail.com.au/~mjhodson/papers/papers.html
 Unfortunately, I've hit a snag.  The library in its current state is usable,
the
 threads can be run, suspended, resumed and killed, but there are no exceptions.
 Are there any documents out there on how D's exceptions work or any other sorts
 of info?  I tried sorting it out from the source in deh.c, but it's rather
 complex.
That's the place to look. Basically, the Windows exception handling mechanism builds upon Structured Exception Handling in some respects, but the stack unwinding is done manually. I'm not sure what you're trying to accomplish, but perhaps it would be enough to wrap the run() function in a try/catch block that passes the exception somewhere appropriate? Sean
Nov 29 2005
parent reply mclysenk mtu.edu writes:
In article <dmid5r$24jc$1 digitaldaemon.com>, Sean Kelly says...
http://members.ozemail.com.au/~mjhodson/papers/papers.html
This sounds sort of like the implementation I was looking at, but I couldn't find any source code or downloads.
 Unfortunately, I've hit a snag.  The library in its current state is usable,
the
 threads can be run, suspended, resumed and killed, but there are no exceptions.
 Are there any documents out there on how D's exceptions work or any other sorts
 of info?  I tried sorting it out from the source in deh.c, but it's rather
 complex.
That's the place to look. Basically, the Windows exception handling mechanism builds upon Structured Exception Handling in some respects, but the stack unwinding is done manually. I'm not sure what you're trying to accomplish, but perhaps it would be enough to wrap the run() function in a try/catch block that passes the exception somewhere appropriate?
I tried that. Exceptions just kill the program outright, not even the typical "This program has generated an error" dialog box. Another issue that needs to be resolved, is that when a try-catch block is used in a stack thread, it links itself in the SEH chain. If that thread yields in the block, it needs to save the SEH information otherwise the global exception handling information will become corrupted. What information besides FS:[0] do I need to save if I want to keep the exception handling stuff intact between threads? I'm posting the source code in case anyone wants to look at it. begin 0644 stackthread.d M+RHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ M*BHJ*BHJ* T*("H 4W1A8VM4:')E860-"B`J($%55$A/4CH-"B`J"4UI:V]L M82!,>7-E;FMO("AM8VQY<V5N:T!M='4N961U*0T*("H-"B`J($1%4T-225!4 M24].. T*("H)5&AI<R!L:6)R87)Y(&AA<R!A('-E="!O9B!P<FEM:71I=F5S M<F5A9', 8GD 9VEV:6YG('1H96T 80T*("H)9&5L96=A=&4 =VAI8V :7, M860 ;&]C86P <W1O<F%G92P <VEN8V4 =&AE(&1E;&5G871E<R!S;VQV90T* M(&UU=&5X97,O<V5M87!H;W)E<R!S:6YC92!T:&4-"B`J"7-T86-K=&AR96%D M(&]V97)H96%D(&9O<B!A('-T86-K('1H<F5A9"!I<R!F86ER;'D ;&]W+`T* M("H)<FEG:'0 ;F]W($D :&%V92!I="!F:7AE9"!A="!A<F]U;F0 ?C)K(&]F M(')A;2P-"B`J"6%N9"!C;VYT97AT('-W:71C:&5S(&]C8W5R('9E<GD <75I M+ T*("H)=6YI='1E<W1S(&%R92!I;F-O;7!L971E+ T*("H)9&]C=6UE;G1A M9"YS=&1I;SL-" T*9FEN86P <VEZ95]T(%-404-+5$A214%$7U-)6D4)/2`R M+R!4:&4 <W1A8VL =&AR96%D(&-L87-S+ T*<'5B;&EC(&-L87-S(%-T86-K M<V5R="AS=&%C:U]S:7IE(#X M(&]F('1H92!S=&%C:R!T:')E861S(&9O<B!O;F4 ='5R; T*"7-T871I8R!V M=6QL*0T*"0D)<F5T=7)N.PT*"0D-" D)=W)I=&5F;&XH(E)U;FYI;F< 82!S M:6YG;&4 <W1A8VL =&AR96%D('1I;65S;&EC92(I.PT*"0EE>&-E<'0 /2!N M*")9:65L9&EN9R!S=&%C:R!T:')E860 <W`])3AX(BP 8W5R+G-P*3L-" D) M9"!S<#TE. M=&EO;B!P<F5E;7!T:79E;'D-" ES=&%T:6, =F]I9"!F:6YI<V H*0T*"7L- M;B B5&AE860 <W`])3AX(&ES(&9I;FES:&EN9R!T:&4 =&EM97-L:6-E(BP M" D):68H(7-U<W!E;F1E9"!\?"!D96%D*0T*"0D)<F5T=7)N.PT*"0D-" D) M=W)I=&5F;&XH(E)E<W5M:6YG('1H<F5A9"!S<#TE. M86< 87, ;F]N('-U<W!E;F1E9`T*"0ES=7-P96YD960 /2!F86QS93L-" D) M*RMN=6U?<G5N;FEN9U]T:')E861S.PT*"7T-" D-" DO+R!3=7-P96YD(&$ M9"!S<#TE. M"0D-" D)=W)I=&5F;&XH(DMI;&QI;F< =&AR96%D('-P/24X>"(L('-P*3L- M"0ES=&0N9V,N<F5M;W9E4F%N9V4H)G-T86-K6S!=*3L-" D)+2UN=6U?=&AR M=7, 8FET<PT*"6)I="!I<U)U;FYI;F<H*2![(')E='5R;B`H=&AI<R!I<R!C M="!I<U-U<W!E;F1E9" I('L <F5T=7)N('-U<W!E;F1E9#L ?0T*"0T*"2\O M*2![(')E='5R;B!N=6U?=&AR96%D<SL ?0T*"7-T871I8R!I;G0 8V]U;G12 M=6YN:6YG5&AR96%D<R I('L <F5T=7)N(&YU;5]R=6YN:6YG7W1H<F5A9',[ M('T-" T*<')I=F%T93H-" D-" EB:70 <W5S<&5N9&5D(#T =')U93L-" EB M"3T ,#L-" ES=&%T:6, =6EN="!N=6U?<G5N;FEN9U]T:')E861S"3T ,#L- M" T*"7-T871I8R!3=&%C:U1H<F5A9`EH96%D"3T ;G5L;#L-" ES=&%T:6, M<W1A=&EC($]B:F5C=`D)97AC97!T"3T ;G5L;#L-" T*"2\O($QI;FL =&AE M('1H<F5A9"!I;G1O('1H92!S8VAE9'5L97( ;&ES=`T*"79O:60 ;&EN:R I M92!C=7)R96YT;'D <G5N;FEN9R!3=&%C:U1H<F5A9"!A9G1E< T*"2\O(&ET M5&AR96%D('-P/24X>"!G96YE<F%T960 86X 97AC97!T:6]N.B`B+"!C=7(N M;6%I;B!T:')E860 8V%T8VAE<R!I=`T*"0D)97AC97!T(#T 93L-" D)"0T* M"0D)+R]+:6QL('1H<F5A9"!T:&%T(&=E;F5R871E9"!T:&4 97AC97!T:6]N M?0T*"0T*"2\O($EN:71I86QI>F4 =&AE('-T86-K(&9O<B!T:&ES('1H<F5A M9"X-" EV;VED('-E='5P4W1A8VLH*0T*"7L-" D)=F]I9"!P=7-H*'5I;G0 M<"`]("AV/CX^,38I("8 ,'AF9CL-" D)"2HM+7-P(#T M+R!);FET:6%L:7IE('-T86-K('!O:6YT97(-" D)<W` /2`H)G-T86-K6VQE M<W1A<G14:')E860-" D)<'5S:"AC87-T*'5I;G0I)G-T87)T5&AR96%D*3L- M1D9&1D9&1BD["0DO+T93.ELP70T*"0D-" D)+R\ 061D('1H:7, =&\ =&AE M,%TL("9S=&%C:UML96YG=& M,5TI.PT*"0D-" D)+R\ 26YC<F5M96YT('1H M92!T:')E860 8V]U;G1E< T*"0DK*VYU;5]T:')E861S.PT*"7T-" T*"2\O M(%-A=F4 =&AE(&-O;G1E>'0 9F]R('1H92!C86QL97( =&AR96%D+ T*"79O M+F]L9'-P72P 15-0.PT*"0D)9G-A=F4 6U-T86-K5&AR96%D+F]L9%]F<'5= M"0EP;W!A9#L-" D)"7)E=#L-" D)?0T*"7T-" D-" DO+R!2971U<FX =&\ M="!P='( 1E,Z6S!=.PT*"0D);6]V('-P6T5!6%TL($534#L-" D)"69S879E M;6]R92!T:')E861S+ T*"0D);6]V(%M3=&%C:U1H<F5A9"YC=7)=+"`P.PT* M($534"P 6U-T86-K5&AR96%D+F]L9'-P73L-" D)"7!O<"!I;G0 <'1R($93 M.ELP73L-" D)"7!O<&%D.PT*"0D)9G)S=&]R(%M3=&%C:U1H<F5A9"YO;&1? M9G!U73L-" D)"7)E=#L-" D)?0T*"7T-" T*"2\O($QO860 )B!R=6X 82!S M"0EN86ME9#L-" D)"0T*"0D)+R\ 4V%V92!O;&0 <W1A=&4-" D)"7!U<VAA M9#L- M8VQE(&QI<W0-" D)"6UO=B!%0E L(&YE>'1;14%873L-" D)"6UO=B!;4W1A M90T*"0D)9G)S=&]R(&9P=5]S=&%T95M%0EA=.PT*"0D);6]V($534"P <W!; M14)873L-" D)"7!O<"!I;G0 <'1R($93.ELP73L-" D)"7!O<&%D.PT*"0D) M;&XH(EQT4G5N;FEN9R!T:')E860 ,B(I.PT*"0D)*RMB.PT*"0D)4W1A8VM4 M"0EF;W(H:6YT(&D],#L M5&AR96%D<R I(#T M/2`P*3L-" E3=&%C:U1H<F5A9"YR=6XH*3L-" EW<FET969L;B B)60 )60 M)60B+"!A+"!B+"!C*3L-" EA<W-E<G0H82`]/2`Q("8F(&( /3T ,2`F)B!C M(#T M9"`E9"(L(&$L(&(L(&,I.PT*"6%S<V5R="AA(#T M)B8 8R`]/2`S*3L-" E3=&%C:U1H<F5A9"YR=6XH*3L-" EW<FET969L;B B M)60 )60 )60B+"!A+"!B+"!C*3L-" EA<W-E<G0H82`]/2`R("8F(&( /3T M,R`F)B!C(#T M" D-" EA(#T ,#L-" EB(#T ,#L- M*RMA.PT*"0D)4W1A8VM4:')E860N>6EE;&0H*3L-" D)?0T*"7TI.PT*"0T* M"5-T86-K5&AR96%D('-T,2`](&YE=R!3=&%C:U1H<F5A9"AD96QE9V%T92!V M;64H*3L-" D-" E3=&%C:U1H<F5A9"YR=6XH*3L-" EW<FET969L;B B)60 M<W0P+G-U<W!E;F0H*3L-" E3=&%C:U1H<F5A9"YR=6XH*3L-" EW<FET969L M;B B)60 )60B+"!A+"!B*3L-" EA<W-E<G0H82`]/2`Q("8F(&( /3T ,BD[ M969L;B B)60 )60B+"!A+"!B*3L-" EA<W-E<G0H82`]/2`Q("8F(&( /3T M"7=R:71E9FQN*"(E9"`E9"(L(&$L(&(I.PT*"6%S<V5R="AA(#T M(&5X8V5P=&EO;B!H86YD;&EN9RXN+B(I.PT*"0D)=&AR;W< ;F5W($5X8V5P M=&EO;B B5&5S="!E>&-E<'1I;VXB*3L-" D)"5-T86-K5&AR96%D+GEI96QD M860H)F5X8V5P=&EO;G,I.PT*"0ET+G)E<W5M92 I.PT*"0E3=&%C:U1H<F5A 65$535`T*=F]I9"!M86EN*"D >WT-" I] ` end
Nov 29 2005
parent reply Frank Benoit <benoit__ __tionex.de> writes:
I am very interested in these stackthreads.
Did you found a solution for the exception problem?
Does this work on linux also?

Frank
Apr 01 2006
parent reply mclysenk mtu.edu writes:
Yes, I was forgetting to set the stack top and stack bottom in the FS register.
I have a working windows version, but unfortunately I don't have linux so I
haven't made a linux release.  Here is the source for the windows code that I am
currently using.  As soon as I am done with classes I will attempt to create a
full library based on the concept, with support for linux.

I intend on creating some more basic synchronization structures as well as
splitting up the scheduler to allow for multiple thread sets.

Mik


In article <e0minm$f7n$1 digitaldaemon.com>, Frank Benoit says...
I am very interested in these stackthreads.
Did you found a solution for the exception problem?
Does this work on linux also?

Frank
begin 0644 qthread.d M+RHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ M;W( 1&EG:71A;&UA<G, 1"X 451H<F5A9',-"B`J(&%R92!V97)Y(&5F9FEC M:65N="P <F5Q=6ER:6YG(&QE<W, =&EM92!P97( 8V]N=&5X=`T*("H <W=I M=&-H('1H86X 9FEB97)S(&]R(')E86P =&AR96%D<RX 451H<F5A9', 8V%N M96YT('-T871E(`T*("H ;6%C:&EN92!D97-I9VX <&%T=&5R;B!S:6YC92!T M:&5Y(&%R92!S;6%L;"!E;F]U9V -"B`J('1H870 =&AO=7-A;F1S(&-A;B!B M;V1I9GD 9G)E96QY+"!J=7-T(&=I=F4 8W)E9&ET+ T*("H 0V]P>7)I9VAT M+R\O(%-T86-K('-I>F4 <&%R86UE=&5R<PT*<'5B;&EC(&-O;G-T('-I>F5? M=&%T=7, ;V8 =&AE('1H<F5A9`T*<'5B;&EC(&5N=6T 451H<F5A9%-T871U M<PT*>PT*"5%42%)%041?4D5!1%DL"0DO+R\ 5V%I=&EN9R!T;R!B92!E>&5C M9RX-" E15$A214%$7U-54U!%3D1%1"P)+R\O"5-U<W!E;F1E9"X-" E15$A2 M" E15$A214%$7T),3T-+140L"2\O+R!!('%T:')E860 :7, 8FQO8VME9`T* M;W)E(&EM<&QE;65N=&%T:6]N(&9O<B!15&AR96%D<RX-"B`J($ET(&UA>2!O M;FQY(&)E('5S960 =VAI;&4 =&AE('-C:&5D=6QE<B!I<R!R=6YN:6YG+ T* M("HJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ M*BHJ*BHJ*BHJ+PT*<'5B;&EC(&-L87-S(%%396UA<&AO<F4-"GL-"G!U8FQI M8SH-" D-" DO*BH-" D *B!);FET:6%L:7IE('1H92!S96UA<&AO<F4 =&\ M=&AE('-P96-I9FEE9"!C;W5N="X-" D * T*"2`J(%!A<F%M<SH-" D * EC M;W5N=%\ /2!4:&4 <V5M87!H;W)E)W, 8V]U;G1E<B!I;FET:6%L('9A;'5E M* T*"2`J(%=A:70 =6YT:6P =&AE('-E;6%P:&]R92!H87, 8F5C;VUE(&%C M=&EV92X-" D *B\-" EV;VED('=A:70H*0T*"7L-" D)87-S97)T*%%4:')E M(#P M*BH-" D *B!3:6=N86P =&AE('-E;6%P:&]R92!T;R!A;&QO=R!T:&4 ;F5X M9"!S:6=N86PH*0T*"7L-" D)87-S97)T*%%4:')E860N9V5T0W5R<F5N=" I M("%I<R!N=6QL*3L-" D)*RMC;W5N=#L- M*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ M*BHJ*BHJ*BH-"B`J($$ 451H<F5A9"!I<R!A('-I;F=L92!U<V5R(&QE=F5L M('1H<F5A9"X 451H<F5A9',-"B`J(&-A;B!B92!T:&]U9VAT(&]F(&%S(')U M("H 5VAE;B!A(%%4:')E860 :7, 8W)E871E9"!I="!I<R!I;6UE9&EA=&5L M>2!A9&1E9`T*("H =&\ =&AE('-C:&5D=6QE<BX 1G)O;2!T:&5R92P =&AE M* T*("H 451H<F5A9', 87)E('%U975E9"!R;W5N9"UR;V)I;B!S='EL92X M($EN(&$ <VEN9VQE(`T*("H =&EM92US;&EC92!E86-H('1H<F5A9"!I<R!A M;&QO=V5D('1O(')U;B!U;G1I;"!I=`T*("H >6EE;&1S+"!T:&5N('1H92!N M97AT('1H<F5A9"!I<R!R=6X 86YD('-O(&]N+ T*("H 06YY(&YE=VQY(&-R M96%T960 =&AR96%D<R!A<F4 ;F]T(')U;B!U;G1I;"!T:&4 ;F5X=`T*("H M<SH-"B`J("TM+2TM+2TM+2TM+2TM+2TM+2TM+0T*("H)+R]$969I;F4 =&AE M('1H<F5A9"!F=6YC=&EO;G,-"B`J"79O:60 =&AR96%D,69U;F,H*0T*("H) M"0EW:&EL92AT<G5E*0T*("H)"7L-"B`J"0D)=W)I=&5F;&XH(E1H<F5A9"`R M('$Q(#T M<3( /2!N97< 451H<F5A9" F=&AR96%D,F9U;F,I.PT*("H-"B`J"2\O(%)U M;B!T:&4 =&AR96%D<PT*("H)=VAI;&4H=')U92D-"B`J"7L-"B`J"0E15&AR M96%D+G)U;B I.PT*("H)?0T*("H-"B`J"2\O5VEL;"!P<FEN=#H-"B`J"2\O M("TM+2TM+2TM+2TM+2TM+2TM+2TM+0T*("HJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ M*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ+PT*<'5B;&EC(&-L M87-S(%%4:')E860-"GL-"G!U8FQI8SH-" D-"B\O+2TM+2TM+2TM+2TM+2TM M+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+0T*+R\ 4T-( M14153$52($953D-424].4PT*+R\M+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM M('-I;F=L92!15&AR96%D('1I;65S;&EC92X 06QL('-C:&5D=6QE9`T*"2`J M('1H<F5A9', 9V5T(&5X96-U=&5D(')O=6YD(')O8FEN('-T>6QE+ T*"2`J M>2!T:&4 =&AR96%D<R!I;B!T:&4-" D * ES;&EC92X-" D *B\-" ES=&%T M:6, =F]I9"!R=6XH*0T*"7L-" D):68H:&5A9"!I<R!N=6QL('Q\(&-U<B`A M;"D-" D)"71H<F]W(&5X8V5P=#L- M=&AE(&-U<G)E;G1L>2!R=6YN:6YG('1I;65S;&EC92X-" D *B\-" ES=&%T M" DO*BH-" D *B!9:65L9"!T:&4 =&AR96%D('-O('1H870 =&AE('-C:&5D M<F5T=7)N.PT*"0D-" D)+R\ 1&5M;W1E('-T871U<R!F<F]M(')U;FYI;F<- M" D)8W5R+G-T871U<R`](%%4:')E8613=&%T=7,N451(4D5!1%]214%$63L- M" D)?0T*"7T-" T*"2\J* T*"2`J($=R86( 82!R969E<F5N8V4 =&\ =&AE M(&-U<G)E;G1L>2!R=6YN:6YG('1H<F5A9"X-" D * T*"2`J(%)E='5R;G,Z M+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM M+2TM+2TM+0T*"2\J* T*"2`J($-R96%T92!A(&YE=R!15&AR96%D('=I=& M82!U<V5R('-P96-I9FEE9"!S=&%C:RX-" D * T*"2`J(%!A<F%M<SH-" D M* EF;B`](%1H92!P<F]C961U<F4 =&AA="!W:6QL(&)E(')U;BX-" D * ES M:7IE(#T 5&AE('-I>F4 ;V8 =&AE('-T86-K+ T*"2`J+PT*"71H:7,H=F]I M9"!D96QE9V%T92 I(&9N+"!S:7IE7W0 <VEZ92`]($1%1D%53%1?4U1!0TM? M4TE:12D-" EI; T*"7L-" D)87-S97)T*&9N*3L-" D)87-S97)T*'-I>F4 M8R`](&9N.PT*"0ES=&%C:RYL96YG=& /2!S:7IE.PT*"0ES971U<%-T86-K M2%)%041?4E5.3DE.1R`F) T*"0D)<W1A='5S("$](%%4:')E8613=&%T=7,N M=&%T=7, /2!15&AR96%D4W1A='5S+E%42%)%041?4U534$5.1$5$.PT*"0ER M<F5A9%-T871U<RY15$A214%$7U-54U!%3D1%1"D-" D)>PT*"0D)<F5T=7)N M"0EW:&EL92AS=&%T=7, (3T 451H<F5A9%-T871U<RY15$A214%$7U1%4DU) M2%)%041?0DQ/0TM%1#L- M(&MI;&PH*0T*"7L-" D):68H<W1A='5S(#T](%%4:')E8613=&%T=7,N451( M4D5!1%]415)-24Y!5$5$*0T*"0D)<F5T=7)N.PT*"0D-" D)9FEN:7-H5&AR M97, =&AE(&-U<G)E;G0 <W1A='5S(&]F('1H92!T:')E860-" D *B\-" E1 M35!,14U%3E1!5$E/3 T*+R\M+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM M*B\-" E15&AR96%D(&YE>'0 /2!N=6QL.PDO+R!.97AT('1H<F5A9"!I;B!S M<W1A=&EC(%%4:')E860 :&5A9"`](&YU;&P["2\O(%-T87)T(&]F('1H92!L M:&4 ;&ES=`T*"7-T871I8R!15&AR96%D(&-U<B`](&YU;&P["2\O($-U<G)E M9"!I;G1O('1H92!S8VAE9'5L97( ;&ES="X-" EV;VED(&QI;FLH*0T*"7L- M"0D):&5A9"YP<F5V(#T =&AI<SL-" D):68H=&%I;"!I<R!N=6QL*0T*"0D) M56YL:6YK('1H:7, =&AR96%D(&9R;VT =&AE('-C:&5D=6QE<B!L:7-T+ T* M=6QL*0T*"0D);F5X="YP<F5V(#T M/2!N=6QL.PT*"7T-" D-" D-"B\O+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM M2$E.1R!)35!,14U%3E1!5$E/3 T*+R\M+2TM+2TM+2TM+2TM+2TM+2TM+2TM M+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM+2TM"0T*"2\J(%1H<F5A9"!) M<W` /2!N=6QL.PD)+R]4:')E860 <W1A8VL <&]I;G1E< T*"79O:60 9&5L M;VQD7W-P(#T ;G5L;#L M=&EC($]B:F5C="!E>&-E<'0 /2!N=6QL.PDO+TQA<W0 9V5N97)A=&5D(&5X M" D)"6-U<BYK:6QL*"D["0DO+U=H96X :70 <F5T=7)N<RP :VEL;"!I="X- M" D)?0T*"0EC871C:"A/8FIE8W0 92D-" D)>PT*"0D)+R]3879E(&5X8V5P M=&EO; T*"0D)97AC97!T(#T 93L-" D)"0T*"0D)+R\ 1FEN86QI>F4O<F5M M;W9E('1H<F5A9`T*"0D)8W5R+F9I;FES:%1H<F5A9" I.PT*"0D)8W5R+G5N M" DO+R!&:6YI<VAE<R!A;GD :6YC;VUP;&5T92!T87-K<R!F;W( =&AE('1H M9V,N<F5M;W9E4F%N9V4H)G-T86-K6S!=*3L-" D)<W1A='5S(#T 451H<F5A M92!T:&ES('1H<F5A9"!F<F]M('1H92!S8VAE9'5L97(L(&]P=&EO;F%L;'D- M:6%L:7IE('1H92!S=&%C:RX (%1H:7, :7, :6UP;&5M96YT871I;VX-" DO M+R\ 86QO;F< =VET:"!T:&4 87-S96UB;&5R+ T*"79O:60 <V5T=7!3=&%C M=F]I9"!P=7-H*'5I;G0 =BD-" D)>PT*"0D)*BTM<W` /2`H=CX^/C(T*2`F M(#T M86YG97,-" D)<W` /2`H)G-T86-K6VQE;F=T:"TQ72D *R`Q.PT*"0EU:6YT M('-T86-K7W1O<"`](&-A<W0H=6EN="DH<W`I.PT*"0EU:6YT('-T86-K7V)O M9"D-" D)<'5S:" P*3L)"0D)+R]%05 -" D)<'5S:" P*3L)"0D)+R]%0U - M" D)<'5S:" P*3L)"0D)+R]%1% -" D)<'5S:" P*3L)"0D)+R]%0E -" D) M1D8I.PD)+R]%0E`-" D)<'5S:" P*3L)"0D)+R]%4TD-" D)<'5S:" P*3L) M"B` ("` ("` ("` ("\O4F5S=&]R92!%0U -"B` ("` ("` ("` ('!O<"!% M<'5S:" P>$9&1D9&1D9&*3L)"2\O1E,Z6S!=(%-%2`T*"0EP=7-H*'-T86-K M7W1O<"D["0DO+T93.ELT72!3=&%C:R!T;W`-" D)<'5S:"AS=&%C:U]B;W0I M" D)<W1D+F=C+F%D9%)A;F=E*`T*"0D)8V%S="AV;VED*BES=&%C:U]T;W`L M=7-H(&EN="!P='( 1E,Z6S1=.PT*"0D)<'5S:"!I;G0 <'1R($93.ELX73L- M;W8 <W1A='5S6T5!6%TL(%%4:')E8613=&%T=7,N451(4D5!1%]254Y.24Y' M15-0+"!S<%M%05A=.PT*"0D)<&]P(&EN="!P='( 1E,Z6SA=.PT*"0D)<&]P M(&EN="!P='( 1E,Z6S1=.PT*"0D)<&]P(&EN="!P='( 1E,Z6S!=.PT*"0D) M"0D-" D)"7)E=#L-" D)?0T*"7T-" D-" DO+R!297-T;W)E(&-O;G1E>'0 M>'0-" D)"7!U<VAA9#L- M4U!=.PT*"0D)<'5S:"!I;G0 <'1R($93.ELP73L-" D)"7!U<V :6YT('!T M6T5!6%TL($534#L-" D)"0T*"0D)+R\ 4V5T(&-U<G)E;G0 <71H<F5A9"!T M6U%4:')E860N;VQD7W-P73L-" D)"7!O<"!I;G0 <'1R($93.ELX73L-" D) M"7!O<"!I;G0 <'1R($93.ELT73L-" D)"7!O<"!I;G0 <'1R($93.ELP73L- M96%D(&-O;G1E>'0 =VAI;&4 <G5N;FEN9PT*"79O:60 <V5T0V]N=&5X=" I M=7)R96YT('%T:')E860 8V]N=&5X=`T*"0D)<'5S:&%D.PT*"0D)<W5B($53 M6S!=.PT*"0D)<'5S:"!I;G0 <'1R($93.ELT73L-" D)"7!U<V :6YT('!T M"6UO=B!%0E L(%MC=7)=.PT*"0D);6]V('-P6T5"6%TL($534#L-" D)"0T* M8W5R72P 14%8.PT*"0D);6]V('-T871U<UM%05A=+"!15&AR96%D4W1A='5S M+E%42%)%041?4E5.3DE.1SL-" D)"0T*"0D)+R]297-T;W)E('%T:')E860 M8V]N=&5X=`T*"0D);6]V($534"P <W!;14%873L-" D)"7!O<"!I;G0 <'1R M($93.ELX73L-" D)"7!O<"!I;G0 <'1R($93.ELT73L-" D)"7!O<"!I;G0 M.#L- M('1E<W0L(&IU<W0 <G5N(&$ 9F5W('1H<F5A9',-" EI;G0 82P 8BP 8SL- M" D-" EA(#T ,#L-" EB(#T ,#L-" EC(#T ,#L-" D-" EV;VED(&9N,2 I M" D)"5%4:')E860N>6EE;&0H*3L-" D)?0T*"7T-" D-" EV;VED(&9N,B I M" D)"5%4:')E860N>6EE;&0H*3L-" D)?0T*"7T-" D-" EV;VED(&9N,R I M" D)"5%4:')E860N>6EE;&0H*3L-" D)?0T*"7T-" D-" E15&AR96%D('0Q M(#T M" D-" EA<W-E<G0H82`]/2`P("8F(&( /3T ,"`F)B!C(#T M/2`Q*3L-" E15&AR96%D+G)U;B I.PT*"6%S<V5R="AA(#T M/2`R("8F(&( /3T ,R`F)B!C(#T M87-S97)T*&$ /3T ,B`F)B!B(#T M969L;B B0F%S:6, =&5S="!P87-S960B*3L-"GT-" T*=6YI='1E<W0-"GL- M="!B(#T ,#L-" D-" E15&AR96%D('4P(#T ;F5W(%%4:')E860H9&5L96=A M*&$ /3T ,B`F)B!B(#T M97)T*&$ /3T ,R`F)B!B(#T M96%D+G)U;B I.PT*"6%S<V5R="AA(#T M"71R>0T*"7L-" D)451H<F5A9"!V,"`](&YE=R!15&AR96%D*&1E;&5G871E M(#T (BP 9C$I.PT*("` ("` ("!A<W-E<G0H9C$ /3T ,3`P+C`I.PT*("` M("` ("`-"B` ("` ("` 451H<F5A9"YY:65L9" I.PT*("` ("` ("`-"B` M("` ("` 9C$ *ST -3`N,#L-"B` ("` ("` =W)I=&5F;&XH(F8Q(#T (BP M9C$I.PT*("` ("` ("!A<W-E<G0H9C$ /3T ,34P+C`I.PT*("` ("` ("`- M"B` ("` ("` 451H<F5A9"YY:65L9" I.PT*("` ('TI.PT*("` (`T*("` M9FQN*")F,B`]("(L(&8R*3L-"B` ("` ("` 87-S97)T*&8R(#T M(F8R(#T (BP 9C(I.PT*("` ("` ("!A<W-E<G0H9C( /3T +3 P,"XP*3L- M96%L(&8S(#T M87-S97)T*&8S(#T M:71E9FQN*")F,R`]("(L(&8S*3L-"B` ("!A<W-E<G0H9C, /3T +3 S+C`I M*&8S(#T]("TX,RXP*3L-"B` ("!F,R`J/2`R.PT*("` ('=R:71E9FQN*")F M,R`]("(L(&8S*3L-"B` ("!A<W-E<G0H9C, /3T +3$V-BXP*3L-"GT-" T* M=6YI='1E<W0-"GL-" DO+R!497-T(&IO:6XO<W5S<&5N9"]R97-U;64-"GT- H" T*=6YI='1E<W0-"GL-" DO+R!497-T('-E;6%P:&]R97,-"GT-"F4- ` end
Apr 02 2006
parent reply Frank Benoit <benoit__ __tionex.de> writes:
mclysenk mtu.edu schrieb:
 As soon as I am done with classes I will attempt to create a
 full library based on the concept, with support for linux.
That would be great. What I do not understand is ... Is this complete saving of context really necessary? There is no action which is interrupted. If you have only cooperative thread switches, than the switches always occurs in a yield function. Isn't it enough to set the stackpointer to the other thread and return? I think of an environment where there is one initial thread (called master). It can create StackThreads as slaves. Switching is allway only cooperative and is only between the master and his slaves. The master thread is also the scheduler. The master has to have a loop where he calls the slaves, until all slaves are complete. Switching than should be lightning fast. I need this for simulation threads. Each thread does one kind of job. If the thread wants to proceed in time, he can increment his local time and yield. The master allways calls the slave with the lowest local time. The whole cluster is a normal pthread and can be interrupted preemptive by other pthreads. There are so many switches between these simulation threads, i think StackThreads can really boost the performance.
Apr 03 2006
parent mclysenk mtu.edu writes:
What I do not understand is ...
Is this complete saving of context really necessary? There is no action
which is interrupted. If you have only cooperative thread switches, than
the switches always occurs in a yield function. Isn't it enough to set
the stackpointer to the other thread and return?
Upon consideration, you are correct, I am saving more information than is necessary. There is no practical reason to maintain the entire floating point state. However, it is still necessary to save the base pointer as well as the context info in FS, and any other information required by a function call.
I think of an environment where there is one initial thread (called
master). It can create StackThreads as slaves. Switching is allway only
cooperative and is only between the master and his slaves. The master
thread is also the scheduler. The master has to have a loop where he
calls the slaves, until all slaves are complete.
Switching than should be lightning fast.
That's the idea. It's also nice to have 'simple' concurrency for state machines. For lots of concurrent state machines, stack threads are a better system than the traditional approach, which is to use a gigantic switch statement. Moreover, they don't have complex synchronization issues like regular threads, since they are nonpreemptive. I've actually been using them in several of my school projects, and even with the very simple scheduler used in the current version, it has greatly simplified many of my projects. Once I get some more time, I will conduct a more thorough investigation of their merits and implentation. Mik
Apr 04 2006