[lkml]   [1996]   [Apr]   [30]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
SubjectRe: SUMMARY: Kernel Threads Usable By Mortals (David S. Miller)  wrote on 28.04.96 in <>:

> Date: 28 Apr 1996 14:56:00 +0200
> From: (Kai Henningsen)
> There's simply no way to get this right without some sort of help
> from the kernel.
> Why not:
> void acquire_lock(lock)
> {
> repeat:
> while(mutex_held(lock))
> yield();
> if(!mutex_try(lock))
> goto repeat;
> }

yield() _is_ "some sort of help from the kernel", isn't it? :-)

However, the above is only safe if neither mutex_* function uses
spinlocks, or at least not without a spin limit.

And you still waste cpu time while your lock is held by some other thread,
only not as much s before.

So I'd say that, while it works, I wouldn't call it "right".

Now, modify that yield() call so it passes a reference to lock to the
kernel, and note somewhere in lock that you are doing so. Have
release_lock look at this and notify the kernel. Have the kernel awaken
your process only after such a notification.

Of course, this needs some more checks to avoid races, but it looks
workable to me - and it should not be that much kernel code.

And of course, the important thing is that the kernel only gets involved
if we need to block, not every time.

MfG Kai

 \ /
  Last update: 2005-03-22 13:37    [W:0.044 / U:1.820 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site