Re: Threads in linux.

Carlos Costa Portela (ccosta@servidores.net)
Thu, 19 Aug 1999 11:37:34 +0200 (CET)


Hello all!

Thank you very much for your info. Basically, I can conclude the next:

+ we have clone(), that implements threads at kernel level.
+ we have pthreads lib, that implements threads using clone().

Some of you said that threads are not implemented at kernel level, but
perhaps this is not 100% correct. Alan said there is no difference between
processes and threads... so my question was stupid [the last words are
mine, not Alan's].

Then, I try to go to the code:

This is the function that do fork() and clone(), threads and processes:

int do_fork(unsigned long clone_flags, unsigned long usp, struct pt_regs
*regs)

In the clone_flags var, we specify what to do:

if (copy_files(clone_flags, p))
goto bad_fork_cleanup;
if (copy_fs(clone_flags, p))
goto bad_fork_cleanup_files;
if (copy_sighand(clone_flags, p))
goto bad_fork_cleanup_fs;
if (copy_mm(nr, clone_flags, p))
goto bad_fork_cleanup_sighand;
retval = copy_thread(nr, clone_flags, usp, p, regs);
if (retval)
goto bad_fork_cleanup_sighand;

Each of this functions copy_*() examine what to do. For example:

if (clone_flags & CLONE_VM) {
mmget(current->mm);
/*
* Set up the LDT descriptor for the clone task.
*/
copy_segments(nr, tsk, NULL);

...

So we can conclude that threads are implemented at kernel level. :-?.

Best regards, and thank you very much again,
Carlos.

_______Carlos Costa Portela__________________________________________
| e-mail: ccosta@servidores.net | http://www.registros.net |
| www: http://ccp.servidores.net | http://www.avisaboe.com |
|http://compuconsejos.servidores.net| http://moana.servidores.net |
|__Tódalas persoas maiores foron nenos antes, pero poucas se lembran__|

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/