[POSIX] implementation of pthread_create()

overflow_ overflow_ at libero.it
Wed Mar 4 12:56:49 UTC 2009



overflow_ wrote:
> 
> Hello to everybody.
> 
> I would like to know
> 
> 1) How is implemented the method pthread_create() in Linux? I mean, does
> it use a call to the clone() function or to fork()?
> 
> 2) where is the implementation of pthread_create()? I know it's declared
> in thread.h, but where its implementation is located?
> 
> Thank you very much
> 

Hello,

Thanks for the help, I think I got it, even if I have still something not
completely clear.

- The implementation of pthread_create is in the glibc in the file
.../nptl/pthread_create.c
Here there is this code libe


> compat_symbol (libpthread, __pthread_create_2_0, pthread_create,
> GLIBC_2_0);
> 
I think this just convert the pthread_create declaration in function
__pthread_create_2_0. I am not sure for it, and if what I have said is wrong
please tell me. I didn't find any documentation.

- the function La funzione __pthread_create_2_0 initialize some field of
attr concerning the scheduling and then call __pthread_create_2_1

- the function __pthread_create_2_1  sets some field in the pthread pointer
and then calls create_thread 

- create_thread is implemented in the file
.../nptl/sysdeps/pthread/createthread.c and it sets the flag of the clone
function in order to create a lightweight process.
int clone_flags = (CLONE_VM | CLONE_FS | CLONE_FILES | CLONE_SIGNAL
           | CLONE_SETTLS | CLONE_PARENT_SETTID
           | CLONE_CHILD_CLEARTID | CLONE_SYSVSEM
           | CLONE_DETACHED )
and then call do_clone
after the call if fills the fields of the structure with the correct data.

- in the do_clone function there ISN'T ANY CALL TO the clone function!!!!!!!
there is just a INTERNAL_SYSCALL call.

it uses just a macro ARCH_CLONE, that call the function __clone, but I
dind't find where is it implemented
I think its implementation changes with the hardware, but I didn't find
where is it! Is there someone that know it? 

Thanks
-- 
View this message in context: http://www.nabble.com/-POSIX--implementation-of-pthread_create%28%29-tp22275000p22329484.html
Sent from the ubuntu-users mailing list archive at Nabble.com.





More information about the ubuntu-users mailing list