_lwp_* system calls?

_lwp_* system calls?

Post by justin.kolodz.. » Sun, 24 Oct 1999 04:00:00



Is there any reason to use the lightweight process system calls directly
in a program instead of using Solaris threads or pthreads?

The Wine project currently uses them to emulate the Windows threading
model, but it is incredibly unstable on Solaris compared to Linux.  I'm
wondering if that has something to do with the following use of
lightweight processes:

ucontext_t context;
_lwp_makecontext( &context, (void(*)(void *))SYSDEPS_StartThread, teb,
                      NULL, teb->stack_base, (char *)teb->stack_top
-                          (char *)teb->stack_base );
    if ( _lwp_create( &context, 0, NULL ) )
        return -1;
    return 0;

What we're trying to do is translate the following Linux-specific code:

#ifdef HAVE_CLONE_SYSCALL
    if (clone( (int (*)(void *))SYSDEPS_StartThread, teb->stack_top,
               CLONE_VM | CLONE_FS | CLONE_FILES | SIGCHLD, teb ) < 0)
        return -1;
    /* FIXME: close the child socket in the parent process */
/*    close( thread->socket );*/
    return 0;
#endif

with something that does the equivalent.  Sun's score utility says to
use vfork, but it seems we need more options than zero.

Sent via Deja.com http://www.deja.com/
Before you buy.

 
 
 

_lwp_* system calls?

Post by Andrew Gabri » Sun, 24 Oct 1999 04:00:00




Quote:>Is there any reason to use the lightweight process system calls directly
>in a program instead of using Solaris threads or pthreads?

>The Wine project currently uses them to emulate the Windows threading
>model, but it is incredibly unstable on Solaris compared to Linux.

I think if you go in at the _lwp_* level, you might well be
below the level at which things like malloc and stdio are
thread-safe. In other words, the section 3 functions which
are thread-safe by being thread-aware, probably aren't
thread-safe any more.

However, I'm by no means certain of this...

--
Andrew Gabriel
Consultant Software Engineer

 
 
 

_lwp_* system calls?

Post by 4wg7kolod.. » Mon, 25 Oct 1999 04:00:00






> >Is there any reason to use the lightweight process system calls
directly
> >in a program instead of using Solaris threads or pthreads?

> >The Wine project currently uses them to emulate the Windows threading
> >model, but it is incredibly unstable on Solaris compared to Linux.

> I think if you go in at the _lwp_* level, you might well be
> below the level at which things like malloc and stdio are
> thread-safe. In other words, the section 3 functions which
> are thread-safe by being thread-aware, probably aren't
> thread-safe any more.

According to the man page:

     Applications  should  use  bound  threads  rather  than  the
     _lwp_*()   functions   (see   thr_create(3T)).  Using   LWPs
     directly is not advised because libraries are only  safe  to
     use with threads, not LWPs.

It also mentions sleep and alarm being per-process, not per-LWP.

So that probably explains the weird behavior.  At least I only have to
change a few lines of code to experiment with it.

Sent via Deja.com http://www.deja.com/
Before you buy.

 
 
 

_lwp_* system calls?

Post by Roger A. Faulkn » Mon, 25 Oct 1999 04:00:00






>>Is there any reason to use the lightweight process system calls directly
>>in a program instead of using Solaris threads or pthreads?

>>The Wine project currently uses them to emulate the Windows threading
>>model, but it is incredibly unstable on Solaris compared to Linux.

>I think if you go in at the _lwp_* level, you might well be
>below the level at which things like malloc and stdio are
>thread-safe. In other words, the section 3 functions which
>are thread-safe by being thread-aware, probably aren't
>thread-safe any more.

>However, I'm by no means certain of this...

You are correct.

Functions in libc are thread-safe only if you link with libthread
(libpthread) and avoid all _lwp_*() functions, that is, use only
the standard interfaces (thr_create(), pthread_create(), etc.).

The _lwp_*() interfaces are support functions for libthread.
They are not to be used unless you are writing a replacement
threads library and then you have to get very intimate with libc.

Roger Faulkner