Changes between Version 9 and Version 10 of user_synchro
- Timestamp:
- Oct 9, 2018, 7:49:23 PM (6 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
user_synchro
v9 v10 1 This section describes the ALMOS-MKH implementation of thePOSIX compliant, user-level synchronisation services: mutex, condvar, barrier and semaphore.1 This section describes the ALMOS-MKH implementation of 4 POSIX compliant, user-level synchronisation services: mutex, condvar, barrier and semaphore. 2 2 3 3 [[PageOutline]] … … 27 27 * The '''remote_mutex_create()''' function allocates and initializes a mutex, using an RPC if if the calling thread is not running in the reference cluster. 28 28 * The '''remote_mutex_destroy()''' function destroys a given mutex, using RPC if the calling thread is not running in the reference cluster. 29 * The blocking '''remote_mutex_lock()''' function implements a descheduling policy when the mutex is already taken by another thread : the calling thread registers in the mutex waiting queue, and blocks on THREAD_BLOCKED_USERSYNC.29 * The blocking '''remote_mutex_lock()''' function implements a descheduling policy when the mutex is already taken by another thread : the calling thread registers in the mutex waiting queue, and blocks on the THREAD_BLOCKED_USERSYNC condition. 30 30 * The '''remote_mutex_unlock()''' function unblocks the first waiting thread in the queue, without releasing the mutex, if the queue is not empty. 31 31 … … 42 42 * The '''remote_condvar_create()''' function allocates and initializes a condvar, using an RPC if if the calling thread is not running in the reference cluster. 43 43 * The '''remote_condvar_destroy()''' function destroys a given condvar, using RPC if the calling thread is not running in the reference cluster. 44 * The blocking '''remote_condvar_wait()''' function allows the calling thread to block on THREAD_BLOCKED_USERSYNC, and to register in the condvar waiting queue.44 * The blocking '''remote_condvar_wait()''' function implement a descheduling policy: the calling thread registers in the condvar waiting queue, and blocks on the THREAD_BLOCKED_USERSYNC condition. 45 45 * The '''remote_condvar_signal()''' function allows (another) thread to unblock the first blocked thread waiting on a given condvar. 46 46 * The '''remote_condvar_broadcast()''' function allows (another) thread to unblock all threads waiting on a given condvar. … … 51 51 The user level, POSIX compliant, barrier is defined in the '''pthread''' library, implemented by the [https://www-soc.lip6.fr/trac/almos-mkh/browser/trunk/libs/libpthread/pthread.h pthread.h] and [https://www-soc.lip6.fr/trac/almos-mkh/browser/trunk/libs/libpthread/pthread.c pthread.c] files. 52 52 53 It can be used by a muti-threaded user application to implement a "rendez-vous" for a given number of threads running in different clusters. 53 It can be used by a muti-threaded user application to implement a "rendez-vous" for a given number of threads running in different clusters. As the implementation uses a toggle variable, the same barrier can be safely used several times, as long as the number of expected threads does not change. 54 54 55 55 The kernel implementation of a barrier is defined in the [https://www-soc.lip6.fr/trac/almos-mkh/browser/trunk/kernel/libk/remote_barrier.h remote_barrier.h] and [https://www-soc.lip6.fr/trac/almos-mkh/browser/trunk/kernel/libk/remote_barrier.c remote_barrier.c] files. … … 58 58 * The '''remote_barrier_create()''' function allocates and initializes a barrier, using an RPC if if the calling thread is not running in the reference cluster. 59 59 * The '''remote_barrier_destroy()''' function destroys a given barrier, using RPC if the calling thread is not running in the reference cluster. 60 * The blocking '''remote_barrier_wait()''' function returns only when all expected threads (defined by the remote_barrier_create() function) reach the barrier. As the implementation uses a toggle variable, this barrier can be safely called several times, as long as the number of expected threads does not change.60 * The blocking '''remote_barrier_wait()''' function returns only when all expected threads (defined by the remote_barrier_create() function) reach the barrier. It implement a descheduling policy: when a thread is not the last expected thread, it register in he barrier waiting queue and blocks on the THREAD_BLOCKED_USERSYNC condition. The last thread reset the barrier and unblocks all waiting threads. 61 61 62 62 == E) Semaphore == … … 71 71 * The '''remote_sem_create()''' function allocates and initializes a semaphore, using an RPC if if the calling thread is not running in the reference cluster. 72 72 * The '''remote_sem_destroy()''' function destroys a given semaphore, using RPC if the calling thread is not running in the reference cluster. 73 * The blocking '''remote_sem_wait()''' function returns only when the semaphore has a non-zero value, and has been atomically decremented. If the semaphore has a zero value, the calling thread registers in the semaphore waiting queue, and block on THREAD_BLOCKED_USERSYNC.73 * The blocking '''remote_sem_wait()''' function returns only when the semaphore has a non-zero value, and has been atomically decremented. If the semaphore has a zero value, the calling thread registers in the semaphore waiting queue, and block on the THREAD_BLOCKED_USERSYNC condition. 74 74 * The '''remote_sem_post()''' function atomically increments the semaphore. If the waiting queue is not empty, it unblock all waiting threads. 75 75 * The '''remote_sem_get_value()''' function returns the semaphore current value, without modifying the semaphore state.