ibm-information-center/dist/eclipse/plugins/i5OS.ic.rzahw_5.4.0.1/rzahwgloco.htm

74 lines
4.5 KiB
HTML

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en-us" xml:lang="en-us">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="security" content="public" />
<meta name="Robots" content="index,follow" />
<meta http-equiv="PICS-Label" content='(PICS-1.1 "http://www.icra.org/ratingsv02.html" l gen true r (cz 1 lz 1 nz 1 oz 1 vz 1) "http://www.rsac.org/ratingsv01.html" l gen true r (n 0 s 0 v 0 l 0) "http://www.classify.org/safesurf/" l gen true r (SS~~000 1))' />
<meta name="DC.Type" content="reference" />
<meta name="DC.Title" content="Use global mutexes to run functions that are not threadsafe" />
<meta name="abstract" content="One alternative you should consider when you need to call a function that is not threadsafe is using a global mutual exclusion (mutex) to run these functions." />
<meta name="description" content="One alternative you should consider when you need to call a function that is not threadsafe is using a global mutual exclusion (mutex) to run these functions." />
<meta name="DC.Relation" scheme="URI" content="rzahwnonco.htm" />
<meta name="copyright" content="(C) Copyright IBM Corporation 1998, 2006" />
<meta name="DC.Rights.Owner" content="(C) Copyright IBM Corporation 1998, 2006" />
<meta name="DC.Format" content="XHTML" />
<meta name="DC.Identifier" content="rzahwglo-gloco" />
<meta name="DC.Language" content="en-us" />
<!-- All rights reserved. Licensed Materials Property of IBM -->
<!-- US Government Users Restricted Rights -->
<!-- Use, duplication or disclosure restricted by -->
<!-- GSA ADP Schedule Contract with IBM Corp. -->
<link rel="stylesheet" type="text/css" href="./ibmdita.css" />
<link rel="stylesheet" type="text/css" href="./ic.css" />
<title>Use global mutexes to run functions that are not threadsafe</title>
</head>
<body id="rzahwglo-gloco"><a name="rzahwglo-gloco"><!-- --></a>
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
<h1 class="topictitle1">Use global mutexes to run functions that are not threadsafe</h1>
<div><p>One alternative you should consider when you need to call a function
that is not threadsafe is using a global mutual exclusion (mutex) to run these
functions.</p>
<div class="section"><p>You might try locking a mutex that you call the FOO MUTEX whenever
you call foo(). This works if you know everything about the internal parts
of foo(), but for general operating system functions, this is still
not a completely safe solution.</p>
</div>
<div class="section"><p>For example, API foo() is not threadsafe because it calls API
bar(), which calls threadUnsafeFoo(). The threadUnsafeFoo() function uses
certain storage and control blocks in an unsafe way. In this example, those
storage and control blocks are called DATA1.</p>
</div>
<div class="section"><p>Because the API threadUnsafeFoo() is unsafe, any application or
system service that uses foo() is not threadsafe because using it with multiple
threads might result in damaged data or undefined results.</p>
</div>
<div class="section"><p>Your application also uses a threadsafe API or system service
that is called wiffle(). Wiffle() calls waffle(), which accesses storage and
control blocks DATA1 in a threadsafe manner. (That is waffle() and a group
of other APIs use an internal DATA1 MUTEX).</p>
</div>
<div class="section"><p>Your application does not know the underlying DATA1 connection
between foo() and wiffle() system services. Your application therefore does
not lock the FOO MUTEX before calling wiffle(). When a call to foo() (holding
the FOO MUTEX) occurs at the same time as a call to wiffle(), the application's
use of the not threadsafe function foo() causes DATA1 and whatever it represents
to be damaged.</p>
</div>
<div class="section"><p>As complex as this scenario is, consider how complex resolving
failures is when you do not know the internal details of all the functions
involved. </p>
</div>
<div class="section"><p>Do not try to make operating system services or functions threadsafe
by using your own serialization.</p>
</div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="rzahwnonco.htm" title="Your multithreaded application at times requires access to functions or system services that are not thread safe. There are few completely safe alternatives for calling these functions.">Function calls that are not thread safe</a></div>
</div>
</div>
</body>
</html>