delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/06/28/18:15:28

X-Originating-Host: 202.158.31.3
Organization: http://www.remarq.com: The World's Usenet/Discussions Start Here
Subject: Re: multitasking/threading in DJGPP
Lines: 73
From: batchex <thedark1NOthSPAM AT phreaker DOT net DOT invalid>
Newsgroups: comp.os.msdos.djgpp
Message-ID: <0885b92f.ce7851b0@usw-ex0103-018.remarq.com>
References: <Pine DOT SUN DOT 3 DOT 91 DOT 1000619173815 DOT 27216T-100000 AT is> <394F7CEF DOT C3B04F13 AT crosswinds DOT net> <200006202002 DOT XAA00101 AT alpha DOT netvision DOT net DOT il> <3951E3E6 DOT 34B80384 AT crosswinds DOT net> <07e97600 DOT 58b5dac5 AT usw-ex0101-005 DOT remarq DOT com> <39586AFF DOT 174232E9 AT crosswinds DOT net>
Bytes: 2119
X-Wren-Trace: eJC1nZyFwojDxIydkdGDktOjkJ2HkdGNkI7RnZyQyYLPxJ7Ay4jLzc3fxw==
Date: Wed, 28 Jun 2000 14:18:09 -0700
NNTP-Posting-Host: 10.0.2.18
X-Complaints-To: wrenabuse AT remarq DOT com
X-Trace: WReNphoon3 962227886 10.0.2.18 (Wed, 28 Jun 2000 14:31:26 PDT)
NNTP-Posting-Date: Wed, 28 Jun 2000 14:31:26 PDT
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Cherniavsky Beni <cben AT crosswinds DOT net> wrote:
>
>Maybe you can setup the stack of the new thread in spawn_thread
()
>so that it will return into spawn_thread() - on the new stack.
I
>think that copying spawn_thread()'s stack frame to the new
stack would
>do the job, more or less.  Then you have put the thread
termination
>code in spawn_thread() and have the thread's first function
just return
>to indicate termination.  This resembles a unix-style fork()
called
>from spawn_thread(), which is clean (INHO) but I'm not sure
what's the
>implementation burden of this idea.
>
I like this idea. Here's a pseudo-code of what I'm thinking

spawn_thread(void (*da_func)(), int stack_size)
{
 check if the caller of this function is the main thread
       if it isn't then return;

 modify the main thread's saved EIP to the content of the
current stack position;

 allocate the new thread's stack;
 change the new thread saved ESP to the end of the allocated
block;
 place the address of end_thread() in the end of the allocated
block;

 call da_func();
}

end_thread()
{
 set uninterruptible flag;
 do some cleaning up;
}

task_switcher()
{
 check uninterruptible flag
       if it's true then return;

 do task switch;
}

There are some loose ends though. First, in spawn_thread() there
are no stack cleaning before calling the new thread, so when
there is a task switch to the main thread, the main thread will
likely fail to execute, 'cause C uses stacks for variables if
I'm not mistaken.

Second, if a task switch occurs between the return of a thread
and setting uninterruptible flag in end_trhread(), I dunno what
will happen.

Third, at the end of end_thread(), how to return to the current
working position of the main thread? I'm thinking of calling the
task_switcher() manually at this point.

I'm not familiar with *NIX multitasking. What yield() do? Where
is the difference between external and internal signals?

Thanks for the idea.

Got questions?  Get answers over the phone at Keen.com.
Up to 100 minutes free!
http://www.keen.com

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019