Linux synchronization with FIFO waiting queue -


What are the locks in Linux, where the waiting queue is FIFO? It sounds like such an obvious thing, and even then I found that pthread mutexes are not FIFO, and semaphores are not apparently even FIFA (I'm working on kernel 2.4 (homework) ...

Is there a lock with FIFO's waiting line in Linux, or is there an easy way to create one with the current system?

There is a way to create a simple "ticket lock" line, pthreads primitives Is built on. This should give you some ideas:

  #include & lt; Pthread.h & gt; Typedef structure ticket_lock {pthread_cond_t cond; Pthread_mutex_t mutex; Unsigned long queue_head, qi_tail; } Ticket_lock_t; #defined TICKET_LOCK_INITIALIZER {PTHREAD_COND_INITIALIZER, PTHREAD_MUTEX_INITIALIZER} canceled ticket_lock (ticket_lock_t * tickets) {unsigned long queue_my; Pthread_mutex_lock (& ​​amp; ticket> mutex); Queue_me = Ticket-> Qi_tail ++; While (queue_me! = Ticket-> Qi-head) {pthread_cond_wait (and ticket-> cod, and ticket-> mutes); } Pthread_mutex_unlock (and ticket-> mutes); } Zero Ticket_Anlock (ticket_lock_t * tickets) {pthread_mutex_lock (& ​​amp; Ticket-> mutex); Ticket & gt; Queue_head ++; Pthread_cond_broadcast (& quot; cond); Pthread_mutex_unlock (& ​​amp; ticket> mutex); }  

Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -