Page 1 of 1
Multi-tasking - Processes and Threads
Posted: Thu Nov 28, 2013 3:31 pm
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?
Re: Multi-tasking - Processes and Threads
Posted: Thu Nov 28, 2013 5:42 pm
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
Re: Multi-tasking - Processes and Threads
Posted: Thu Nov 28, 2013 9:02 pm
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.