[uClinux-dev] Threading and synchronization questions
lsorense at csclub.uwaterloo.ca
Fri Feb 27 09:07:28 EST 2009
On Fri, Feb 27, 2009 at 05:57:28AM +0100, Jan Ringo? wrote:
> Well, I am interested in uClinux only, in this case. I still don't see
> the difference. If all the processes live in the same address space here,
> and when I create a thread (pthread_create) I see a new duplicate process
> through ps command (just as if created by vfork), then what can it be,
> that would make pthread_mutex not work?
All processes only live in a single address space due to the fact that
most no mmu systems have only one address space, which is the one the
kernel sees where all memory is directly accessed.
The kernel still keeps track of which memory is used by which process
so as far as the kernel is concerned, each process does have its own
address space, there just isn't any protection in place to prevent a
process from doing anything to another process.
If you do the programing well, no process should ever touch the memory
of another process and the system will run very reliably. Do it badly,
and your pointer mistakes in one program can cause another to crash.
I have always been amazed that the Amiga could run preemptive multitasking
of lots of programs and rarely had any issues given it had no protection
at all, and in fact ran everything very much like uclinux.
So if you want to write good software, you will pretend that each process
has its own memory space and make sure you never try to read an address
that your process doesn't own. If you want to talk to another process,
use a unix socket. If you want everyone to poke at each others memory,
why not just build one single giant executable with threads since at
least then it is obvious to anyone that looks at the code that that is
in fact what you are doing.
More information about the uClinux-dev