4. Mutex
 
  Mutual exclusion (often abbreviated to mutex) algorithms are used in concurrent programming to avoid the simultaneous use of a common resource, such as a global variable, by pieces of computer code called critical sections. A critical section is a piece of code in which a process or thread accesses a common resource.
 
  Examples of such resources are fine-grained flags, counters or queues, used to communicate between code that runs concurrently, such as an application and its interrupt handlers. The synchronization of access to those resources is an acute problem because a thread can be stopped or started at any time.
 
Without Mutex Routine Prefix
int counter=0;


void *ThreadProc()
{
counter++;
}
pthread_mutex_t mutex1 = THREAD_MUTEX_INITIALIZER;
int counter=0;

void functionC()
{
    pthread_mutex_lock( &mutex1 );
    counter++;
    pthread_mutex_unlock( &mutex1 );
}
 
 
 
 
 
이전페이지 / 5 / 다음페이지