Multi-tasking - Processes and Threads

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
BMW
Member
Member
Posts: 286
Joined: Mon Nov 05, 2012 8:31 pm
Location: New Zealand

Multi-tasking - Processes and Threads

Post by BMW »

I have got multi-tasking up and running (with processes), and I was wondering how to implement threads.

If I understand the wiki (Process and Threads) correctly, implementing thread support should be very simple - adding a thread could simply add a 'process' which uses the same address space as the parent process but has a separate stack.

This left me wondering, what's the catch?
Currently developing Lithium OS (LiOS).

Recursive paging saves lives.
"I want to change the world, but they won't give me the source code."
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: Multi-tasking - Processes and Threads

Post by Brendan »

Hi,
BMW wrote:I have got multi-tasking up and running (with processes), and I was wondering how to implement threads.

If I understand the wiki (Process and Threads) correctly, implementing thread support should be very simple - adding a thread could simply add a 'process' which uses the same address space as the parent process but has a separate stack.

This left me wondering, what's the catch?
I find it much easier to think of a process as a container that contains one or more threads.

Basically; a process has a virtual address space and a few other things that the scheduler doesn't care about, and contains one or more threads that the scheduler does care about. When a process is created, its initial thread is also created (and it's this initial thread that begins executing at the process' entry point). If a process has no threads (e.g. its last remaining thread has terminated) then the "thread container" is destroyed.


Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
User avatar
BMW
Member
Member
Posts: 286
Joined: Mon Nov 05, 2012 8:31 pm
Location: New Zealand

Re: Multi-tasking - Processes and Threads

Post by BMW »

Brendan wrote: I find it much easier to think of a process as a container that contains one or more threads.

Basically; a process has a virtual address space and a few other things that the scheduler doesn't care about, and contains one or more threads that the scheduler does care about. When a process is created, its initial thread is also created (and it's this initial thread that begins executing at the process' entry point). If a process has no threads (e.g. its last remaining thread has terminated) then the "thread container" is destroyed.


Cheers,

Brendan
That makes much more sense. Thanks.
Currently developing Lithium OS (LiOS).

Recursive paging saves lives.
"I want to change the world, but they won't give me the source code."
Post Reply