From e230f56b836140f94cb0f3601a862d75bc15d266 Mon Sep 17 00:00:00 2001 From: karim hamidou Date: Wed, 16 Jul 2014 19:01:05 +0200 Subject: [PATCH] fixed code --- _posts/2014-07-15-Russ-Cox.markdown | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/_posts/2014-07-15-Russ-Cox.markdown b/_posts/2014-07-15-Russ-Cox.markdown index ea36e75..1eed856 100644 --- a/_posts/2014-07-15-Russ-Cox.markdown +++ b/_posts/2014-07-15-Russ-Cox.markdown @@ -59,18 +59,18 @@ waits for an acknowledgement from W, and then frees the per-client structure.

To acknowledge the disconnect, W ran code like: -{% highlight c %} +

 qlock(&conn->lk);
 conn->writer_done = 1;
 qsignal(&conn->writer_ack);
 qunlock(&conn->lk);
 thread_exit();
-{% endhighlight %}
+

And to wait for the acknowledgement, R ran code like: -{% highlight c %} +

 qlock(&conn->lk);
 while(!conn->writer_done)
     qwait(&conn->writer_ack);
@@ -78,7 +78,7 @@ while(!conn->writer_done)
 // The writer is done, and so are we:
 // free the connection.
 free(conn);
-{% endhighlight %}
+

This is a standard locks and condition variables piece of code: @@ -116,7 +116,7 @@ This approach is called spinning, and a lock using this approach is called a A simple spin lock implementation looks like: -{% highlight c %} +

 struct SpinLock
 {
     int bit;
@@ -136,7 +136,7 @@ spinunlock(SpinLock *lk)
 {
     atomic_set(&lk->bit, 0);
 }
-{% endhighlight %}
+

The spin lock’s core is the bit field. @@ -163,7 +163,7 @@ Queueing is more efficient than spinning when the lock may be held for a long ti The queue lock’s queue needs its own lock, almost always a spin lock. In the library I was using, qlock and qunlock were implemented as: -{% highlight c %} +

 struct QLock
 {
     SpinLock spin;
@@ -197,7 +197,7 @@ qunlock(QLock *lk)
         os_wakeup(t);
     spinunlock(&lk->spin);
 }
-{% endhighlight %}
+

The queue lock’s core is the owner field. -- 2.43.0