FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Ubuntu > Ubuntu User

 
 
LinkBack Thread Tools
 
Old 03-01-2009, 03:55 PM
overflow_
 
Default implementation of pthread_create()

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
--
View this message in context: http://www.nabble.com/-POSIX--implementation-of-pthread_create%28%29-tp22275000p22275000.html
Sent from the ubuntu-users mailing list archive at Nabble.com.


--
ubuntu-users mailing list
ubuntu-users@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
 
Old 03-01-2009, 04:58 PM
overflow_
 
Default implementation of pthread_create()

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
--
View this message in context: http://www.nabble.com/-POSIX--implementation-of-pthread_create%28%29-tp22275000p22275000.html
Sent from the ubuntu-users mailing list archive at Nabble.com.


--
ubuntu-users mailing list
ubuntu-users@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
 
Old 03-01-2009, 07:33 PM
Mark Kirkwood
 
Default implementation of pthread_create()

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
>
According to this link:

http://linux.die.net/man/7/pthreads

The NPTL (Native Posix Thread Lib - which most Linux disros use now) is
implemented using clone(2) for creation and futex(2) for synchronization.


So maybe the question then becomes "How is clone(2) implementated in LInux"?


In terms of where the implementation is located - I think you need to
download both glibc and kernel sources, as I think there are thread
specific modules in both.


regards

Mark

--
ubuntu-users mailing list
ubuntu-users@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
 
Old 03-01-2009, 07:46 PM
Loc Greni
 
Default implementation of pthread_create()

2009/3/1 overflow_ <overflow_@libero.it>:
> 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()?

With the "standard" implementation (the one you get if you do not
do anything), it uses clone().

> 2) where is the implementation of pthread_create()? I know it's declared in
> thread.h, but where its implementation is located?

It is pthread.h

You can get the sources by typing

apt-get source libc6

(this is a big collection of libraries, but it contains /lib/libpthread-2.7.so
that implements pthread_* functions).

Hope this helps,

Loc

--
ubuntu-users mailing list
ubuntu-users@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
 
Old 03-02-2009, 11:21 AM
Matthew Flaschen
 
Default implementation of pthread_create()

Loc Greni wrote:
> (this is a big collection of libraries, but it contains /lib/libpthread-2.7.so
> that implements pthread_* functions).

Well,/lib/libpthread-2.7.so is not exactly the source. Loc, start at
libc/nptl/pthread_create.c
(http://sourceware.org/cgi-bin/cvsweb.cgi/libc/nptl/pthread_create.c?rev=1.60&content-type=text/x-cvsweb-markup&cvsroot=glibc),
libc/nptl/sysdeps/pthread/createthread.c
(http://sourceware.org/cgi-bin/cvsweb.cgi/libc/nptl/sysdeps/pthread/createthread.c?rev=1.23.2.7&content-type=text/x-cvsweb-markup&cvsroot=glibc).
Obviously, those links aren't the exact sources used by Ubuntu, but
it's a good starting point.

Matt Flaschen

--
ubuntu-users mailing list
ubuntu-users@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
 
Old 03-04-2009, 04:25 AM
Carl Flippin
 
Default implementation of pthread_create()

pthread_create is defined in libpthread.so. In the case of ubuntu, at
least, that library is included as part of libc6. I think you would have
good luck looking and the glibc source code.
--
+---------------------+-----------------------------------------+
|Carl Flippin | If debugging is the process of removing |
|carlf@photocarl.org | software bugs, programming must be the |
|http://photocarl.org | process of putting them in. |
+---------------------+-----------------------------------------+

--
ubuntu-users mailing list
ubuntu-users@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
 
Old 03-04-2009, 11:56 AM
overflow_
 
Default implementation of pthread_create()

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.


--
ubuntu-users mailing list
ubuntu-users@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
 
Old 03-05-2009, 11:15 PM
Carl Flippin
 
Default implementation of pthread_create()

overflow_ <overflow_@libero.it> writes:

> overflow_ wrote:
>
> Thanks for the help, I think I got it, even if I have still something
> not completely clear.
...snip...
>
> - 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?
>

This is expected. Ultimately, most of the glibc functions end up calling
a linux syscall. That's how glibc gets linux to actually do something. I
would expect the final implementation to make a syscall since all the
threading functions ultimately rely on the kernel. You will find this to
be true in most cases.

--
+---------------------+-----------------------------------------+
|Carl Flippin | If debugging is the process of removing |
|carlf@photocarl.org | software bugs, programming must be the |
|http://photocarl.org | process of putting them in. |
+---------------------+-----------------------------------------+

--
ubuntu-users mailing list
ubuntu-users@lists.ubuntu.com
Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-users
 

Thread Tools




All times are GMT. The time now is 02:42 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org