Symbian3/SDK/Source/GUID-FA120B3F-4EC4-5A0A-8A36-D5CD032CF1B0.dita
changeset 0 89d6a7a84779
equal deleted inserted replaced
-1:000000000000 0:89d6a7a84779
       
     1 <?xml version="1.0" encoding="utf-8"?>
       
     2 <!-- Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies) All rights reserved. -->
       
     3 <!-- This component and the accompanying materials are made available under the terms of the License 
       
     4 "Eclipse Public License v1.0" which accompanies this distribution, 
       
     5 and is available at the URL "http://www.eclipse.org/legal/epl-v10.html". -->
       
     6 <!-- Initial Contributors:
       
     7     Nokia Corporation - initial contribution.
       
     8 Contributors: 
       
     9 -->
       
    10 <!DOCTYPE concept
       
    11   PUBLIC "-//OASIS//DTD DITA Concept//EN" "concept.dtd">
       
    12 <concept xml:lang="en" id="GUID-FA120B3F-4EC4-5A0A-8A36-D5CD032CF1B0"><title>Using Mutexes</title><prolog><metadata><keywords/></metadata></prolog><conbody><p>Mutexes provide serialised access to shared resources. They are Kernel objects and, as such, are managed by the Kernel.</p> <p>A mutex can be used by threads across any number of processes. If a resource is only shared between the threads within the same process, it can be more efficient to use a critical section.</p> <p>Access to a mutex is through an RMutex handle.</p> <p>Mutexes are similar to semaphores in that they have a <codeph>TInt</codeph> count value that is incremented by calling the <codeph>Signal()</codeph> member function of the mutex handle and decremented by calling the <codeph>Wait()</codeph> member function of the mutex handle. A mutex with a negative value implies that a thread must wait for access to the shared resource.</p> <p>Unlike a semaphore, the count value of a mutex is always set to one when it is constructed.</p> <p>The creator of a shared resource uses the <codeph>CreateLocal()</codeph> or <codeph>CreateGlobal()</codeph> member functions of <codeph>RMutex</codeph> to create a mutex and to open the handle to it. Any thread wishing to access the resource first calls <codeph>Wait()</codeph>; that thread then calls <codeph>Signal()</codeph> after completing its access.</p> <p>The first thread to call <codeph>Wait()</codeph> returns immediately, and is free to continue execution, but any other threads that call <codeph>Wait()</codeph> will wait in a queue maintained by the mutex. Waiting threads are released on a first-in first-out basis when the thread currently accessing the resource calls <codeph>Signal()</codeph>.</p> <p>The nature of the shared resources should be such that any access completes in a relatively short time so that threads do not wait for extensive periods on the mutex.</p> <p>In many cases, it may be better to use servers to serialize access to a shared resource (for example, the window server) rather than use a mutex. </p> </conbody></concept>