Threading system calls (int 80h)

David Xu davidxu at freebsd.org
Tue Oct 17 02:17:35 PDT 2006


On Tuesday 17 October 2006 16:10, Divacky Roman wrote:
> On Mon, Oct 16, 2006 at 02:08:59PM +0200, Marco van de Voort wrote:
> > > On Sunday 15 October 2006 01:32, David Xu wrote:
> > > > You are going to be unable to use libc if you create raw thread in
> > > > your program, libc uses pthread APIs, if you create a raw thread,
> > > > your program will crash if you use any libc function which needs
> > > > pthread interface.
> > >
> > > I don't want to link to libc. So, how do I create a raw thread?
> >
> > (digging deep into memory)
> >
> > Have a look how the linuxator emulates the clone() syscall with (IIRC)
> > rfork. A limited route, but iirc it works.
>
> linuxolator clone() uses fork1() which is unaccessible from outside kernel.
> there is a "user space implementation" of clone() in linuxthreads which
> uses rfork() but rfork creates "normal processes". but you can pass flags
> to rfork() thus emulation most of the needs of threads (shared memory etc.)
>
> roman

You can use rfork() to create kernel threads, but you won't have POSIX signal
and job control support in kernel, this is also one of important threading 
work in the past. Also rfork() does not allow you to specify user stack, you
have to add some tricky code to make it safe before new
thread really can do real work, plus if you want TLS to work, you have to
do more work, this is why we invent THR syscalls to do all the initializing
work in a single syscall, there are other problems of rfork I can not think of
at the moment.

David Xu


More information about the freebsd-hackers mailing list