More comments on the ticket lock code
This commit is contained in:
@@ -3,7 +3,9 @@
|
||||
|
||||
#include <pthread.h>
|
||||
|
||||
/** An fair alternative to a bare pthread_mutex_t to prevent starvation*/
|
||||
/** An fair alternative to a bare pthread_mutex_t to prevent starvation.
|
||||
* The members of UCTicketLock must never be accessed directly.
|
||||
*/
|
||||
struct UCTicketLock {
|
||||
pthread_cond_t cond;
|
||||
pthread_mutex_t mutex;
|
||||
|
||||
@@ -1,6 +1,13 @@
|
||||
#include <assert.h>
|
||||
#include "ucore/ticket_lock.h"
|
||||
|
||||
//pthread implementation of http://en.wikipedia.org/wiki/Ticket_lock
|
||||
//The underlying phtread mutex is not held while the lock is acquired.
|
||||
//This will allow other threads to enqueue itself.
|
||||
//
|
||||
//The condition variable is needed to wake up threads waiting to acquire
|
||||
//the lock instead of letting the system block on the pthread mutex while waiting.
|
||||
|
||||
int uc_ticket_lock_init(struct UCTicketLock *lock)
|
||||
{
|
||||
return uc_ticket_lock_init_ex(lock, NULL, NULL);
|
||||
|
||||
Reference in New Issue
Block a user