rsnt_translations
56,430
edits
No edit summary |
No edit summary |
||
Line 62: | Line 62: | ||
=Synchronisation de l'accès aux données= | =Synchronisation de l'accès aux données= | ||
Dans un programme en situation réelle, les fils esclaves doivent lire et dans certains cas modifier certaines données afin d'accomplir leurs tâches. Les données sont habituellement un ensemble de variables globales de divers types et dimensions; l'accès concurrent en lecture et en écriture par plusieurs fils doit | Dans un programme en situation réelle, les fils esclaves doivent lire et dans certains cas modifier certaines données afin d'accomplir leurs tâches. Les données sont habituellement un ensemble de variables globales de divers types et dimensions; l'accès concurrent en lecture et en écriture par plusieurs fils doit donc être synchronisé afin d'éviter les [https://en.wikipedia.org/wiki/Race_condition situations de compétition], c'est-à-dire les cas où le résultat du programme dépend de l'ordre dans lequel les fils esclaves accèdent aux données. Si un programme en parallèle doit donner le même résultat que sa version en série, les situations de compétition ne doivent pas se produire. | ||
The simplest and most common way to control the reading and writing of data shared among threads is the [https://en.wikipedia.org/wiki/Lock_(computer_science) mutex], derived from the expression 'mutual exclusion'. In pthreads, a mutex is a kind of variable that may be "locked" or "owned" by only one thread at a time. The thread must then release or unlock the mutex once the global data has been read or modified. The code that lies between the call to lock a mutex and the call to unlock it will only be executed by a single thread at a time. To create a mutex in a pthreads program, we declare a global variable of type <tt>pthread_mutex_t</tt> which must be initialized before it is used by calling <tt>[http://pubs.opengroup.org/onlinepubs/7908799/xsh/pthread_mutex_init.html pthread_mutex_init]</tt>. At the program's end we release the resources associated with the mutex by calling <tt>[http://pubs.opengroup.org/onlinepubs/7908799/xsh/pthread_mutex_init.html pthread_mutex_destroy]</tt>. | The simplest and most common way to control the reading and writing of data shared among threads is the [https://en.wikipedia.org/wiki/Lock_(computer_science) mutex], derived from the expression 'mutual exclusion'. In pthreads, a mutex is a kind of variable that may be "locked" or "owned" by only one thread at a time. The thread must then release or unlock the mutex once the global data has been read or modified. The code that lies between the call to lock a mutex and the call to unlock it will only be executed by a single thread at a time. To create a mutex in a pthreads program, we declare a global variable of type <tt>pthread_mutex_t</tt> which must be initialized before it is used by calling <tt>[http://pubs.opengroup.org/onlinepubs/7908799/xsh/pthread_mutex_init.html pthread_mutex_init]</tt>. At the program's end we release the resources associated with the mutex by calling <tt>[http://pubs.opengroup.org/onlinepubs/7908799/xsh/pthread_mutex_init.html pthread_mutex_destroy]</tt>. |