On Thu, 6 Apr 2000, Matthew Dillon wrote:
>
> :The version of Linux kernel source that I have uses the first:
> :
> :asmlinkage long sys_getppid(void)
> :{
> : int pid;
> : struct task_struct * me = current;
> : struct task_struct * parent;
> :
> : parent = me->p_opptr;
> : for (;;) {
> : pid = parent->pid;
> :#if __SMP__
> :{
> : struct task_struct *old = parent;
> : mb();
> : parent = me->p_opptr;
> : if (old != parent)
> : continue;
> :}
> :#endif
> : break;
> : }
> : return pid;
> :}
> :
> :I like it. mb() is most certainly a "memory barrier" inline to
> :force ordering constraints. interesting how they don't use
> :volatile for the pointer though:
>
> mb() just prevents the compiler from optimizing access to the
> structural fields (otherwise it might move the accesses outside
> the for() loop and you would get an infinite loop. From the
> compiler's point of view, mb() is a subroutine call (I assume
> in the headers it's a volatile __asm).
>
> We can either use an mb() type of thing, or we can declare the structural
> field volatile, or we can cast the access to be volatile.
It also forces the cpu to drain writes and prevents reads from being
re-ordered before the mb(). This is mainly a hint for alpha processors but
I think it is relavent to other architectures.
--
Doug Rabson Mail: [EMAIL PROTECTED]
Nonlinear Systems Ltd. Phone: +44 181 442 9037
To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-current" in the body of the message