Lines Matching +full:shared +full:- +full:memory
8 …formation Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifica…
16 mutex_destroy \- mutual exclusion locks
20 cc -mt [ \fIflag\fR... ] \fIfile\fR... [ \fIlibrary\fR... ]
55 executing critical sections of code that access shared data (that is, mutexes
65 allocated in writable memory and shared among the cooperating processes (see
69 Mutexes are either intra-process or inter-process, depending upon the argument
76 For inter-process synchronization, a mutex needs to be allocated in memory
77 shared between these processes. Since the memory for such a mutex must be
105 object initialized with this attribute must be allocated in memory shared
106 between processes, either in System V shared memory (see \fBshmop\fR(2)) or in
107 memory mapped to a file (see \fBmmap\fR(2)). If the object is not allocated in
108 such shared memory, it will not be shared between processes.
113 The \fItype\fR argument can be augmented by the bitwise-inclusive-\fBOR\fR of
142 The memory for the object to be initialized with this attribute must be zeroed
229 Initializing mutexes can also be accomplished by allocating in zeroed memory
252 Default mutex initialization (intra-process):
273 Customized mutex initialization (inter-process):
283 Customized mutex initialization (inter-process robust):
330 the critical section of code that is enclosed by the mutex-locking call and the
331 mutex-unlocking call, whether the mutex's scope is intra-process or
332 inter-process. A thread calling to lock the mutex either gets exclusive access
444 non-\fBLOCK_RECURSIVE\fR mutex if:
456 The \fBmutex_lock()\fR function may fail for a non-\fBLOCK_ERRORCHECK\fR and
457 non-\fBLOCK_RECURSIVE\fR mutex if:
533 The following example uses one global mutex as a gate-keeper to permit each
534 thread exclusive sequential access to the code within the user-defined
536 state of shared data, but it also prohibits parallelism.
540 /* cc thisfile.c -lthread */
575 /* CC thisfile.c -lthread use C++ to compile*/
607 Global_data--;
623 if ((switcher++ % 3) == 0) /* one-in-three threads subtracts */
634 A mutex can protect data that is shared among processes. The mutex would need
636 process-shared mutex and writes it to a file to be mapped into memory by all
639 mutex-protected data.
643 /* cc thisfile.c -lthread */
653 #define INTERPROCESS_FILE "ipc-sharedfile"
675 /* Initializes the process-shared mutex */
681 buffer->Interprocess_data = 0;
682 mutex_init(&buffer->Interprocess_mutex, USYNC_PROCESS,0);
690 while(ipc_fd = open(INTERPROCESS_FILE, O_RDWR)) == -1)
704 mutex_lock(&buffer->Interprocess_mutex);
705 buffer->Interprocess_data++;
707 printf("%d is add-interprocess data, and %c is argv1\en",
708 buffer->Interprocess_data, argv_1[0]);
709 mutex_unlock(&buffer->Interprocess_mutex);
714 mutex_lock(&buffer->Interprocess_mutex);
715 buffer->Interprocess_data--;
717 printf("%d is subtract-interprocess data, and %c is argv1\en",
718 buffer->Interprocess_data, argv_1[0]);
719 mutex_unlock(&buffer->Interprocess_mutex);
746 A mutex can protect data that is shared among processes robustly. The mutex
748 process initializes the robust process-shared mutex and writes it to a file to
749 be mapped into memory by all cooperating processes (see \fBmmap\fR(2)).
751 concurrently or not) and share mutex-protected data.
759 /* cc thisfile.c -lthread */
766 #define INTERPROCESS_FILE "ipc-sharedfile"
779 while((ipc_fd = open(INTERPROCESS_FILE, O_RDWR)) == -1)
783 mutex_init(&buffer->Interprocess_mutex,
790 buffer->Interprocess_data = 0;
791 mutex_init(&buffer->Interprocess_mutex,
795 rc = mutex_lock(&buffer->Interprocess_mutex);
806 mutex_consistent(&buffer->Interprocess_mutex);
807 mutex_unlock(&buffer->Interprocess_mutex);
819 * There is no error - data is consistent.
822 mutex_unlock(&buffer->Interprocess_mutex);
840 buffer->Interprocess_data = 0;
848 The following example allocates and frees memory in which a mutex is embedded.
858 mutex_init(&r->m, USYNC_THREAD, NULL);
875 mutex_lock(&r->m); mutex_lock(&r->m);
876 r->field1++; localvar = r->field1;
877 mutex_unlock(&r->m); mutex_unlock(&r->m);
884 Later, when a thread decides to free the memory pointed to by \fIr\fR, the
885 thread should call \fBmutex_destroy\fR(\|) on the mutexes in this memory.
889 of the above threads. If there are no other threads using the memory in
896 mutex_destroy(&r->m); /* first destroy mutex */
897 free(r); /* then free memory */
903 If the mutex is not destroyed, the program could have memory leaks.
918 MT-Level MT-Safe
942 containing a locked robust mutex unmapped the memory containing the mutex or