[715] in Pthreads mailing list archive
Re: pthreasds vs. the old lwp library
daemon@ATHENA.MIT.EDU (Cheryl Huntington)
Tue Aug 26 20:26:48 1997
Date: Tue, 26 Aug 1997 17:18:21 -0700
From: Cheryl Huntington <clh@swdc.stratus.com>
To: Ken Johnson <kbj@risc.rockwell.com>
Cc: pthreads@MIT.EDU
Solaris has two thread libraries: libpthread and libthread. libthread
can get closer to what you're looking for if you aren't restricted to
POSIX. It has thr_suspend(), thr_continue(), and thr_yield() in it. The
Solaris 2.5 Multithreaded Programming Guide is a good reference for
this. You can mix libthread and libpthread according to the book.
If you're restricted to POSIX threads, then there is no equivalent to a
resume or yield. The POSIX spec does provide an example of how "suspend
self" and "resume thread" functions could be implemented. It doesn't
promise efficiency though.
struct susp {
struct susp *next;
pthread_t who;
pthread_cont_t w;
} *list;
pthread_mutex_t lock;
void suspend_self(void)
{
struct susp s;
pthread_mutex_lock(&lock);
pthread_cond_init (&s.w (pthread_condattr_t *)NULL);
s.who = pthread_self();
s.next = list;
list = &s;
while (pthread_equal(s.who, pthread_self()))
pthread_cond_wait (&s.w, &lock);
pthread_mutex_unlock (&lock);
}
void resume (pthread_t t)
{
struct susp *p, *q;
pthread_mutex_lock (&lock);
for (q = (struct susp *)&list; p = q->next; q = p)
{
if (pthread_equal (t, p->who))
{
q->next = p->next;
p->who = pthread_self();
pthread_cond_signal (&p->w);
break;
|
}
pthread_mutex_unlock (&lock);
}
Cheryl
--
Cheryl Huntington clh@swdc.stratus.com 408-559-5665
Stratus Western Development Center, Commands and Utilities Group
Ken Johnson wrote:
>
> I recently undertook the long task of porting a whole load of SW
> from solaris 1 to solaris 2.5.1. Wouldn't you know my friends
> at sun changed the stinking operating system so my old libraries
> and there are LOTS of them all needed to be recompiled. One of these
> used the old light weighrt process library. Now I get to learn pthreads.
>
> I am trying unsuccessfuly to mimic five functions from the old lwp with
> pthreads. I can't quite get it to work. ANy thoughts?
>
> lwp_create -> Got this one ok
> lwp_resume -> Can't for the life of me figure out how to fake this
> lwp_yield -> I'd really like this one too
> lwp_destroy -> I figure this is pthread_kill
>
> This is part of a very involved event driven simulator and I really don't have
> time to fiddle.
>
> Any healp is appreciated.
>
> Thanks