Subject: Re: Return value of cpu_switchto(9)
To: Martin Husemann <martin@duskware.de>
From: Matt Thomas <matt@3am-software.com>
List: tech-kern
Date: 05/20/2007 13:58:23
On May 20, 2007, at 1:22 PM, Martin Husemann wrote:

> Hi folks,
>
> reading cpu_switchto(9) I got the impression that, whatever the  
> first arg
> to the function is, it should always return curlwp before the switch:
>
> RETURN VALUES
>      cpu_switchto() does not return until another LWP calls  
> cpu_switchto() to
>      switch to us.  It returns an lwp from which we have been  
> switched, i.e.,
>      an LWP which called cpu_switchto to switch to us.
>
> Now from experiments with sparc64 it seems that this is wrong: it  
> always
> needs to return it's first arg, otherwise we'll hit a lockdebug  
> assertion
> because we try to unlock an lwp twice.
>
> Is the man page wrong, or is this papering over a different bug?

I think the manpage is correct.

switchto(old, x);
switchto(x, tmp);
switchto(tmp, old);
switchto(NULL, tmp); /* old is deleted *.
switchto(tmp, x);

if old was returned, it would be to a deleted lwp and that can't be  
right.