83 lines
5.1 KiB
HTML
83 lines
5.1 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="Thread-specific data" />
|
|
<meta name="abstract" content="Typical applications that are not threaded use global storage." />
|
|
<meta name="description" content="Typical applications that are not threaded use global storage." />
|
|
<meta name="DC.Relation" scheme="URI" content="rzahwmulco.htm" />
|
|
<meta name="DC.Relation" scheme="URI" content="rzahwe21rx.htm" />
|
|
<meta name="DC.Relation" scheme="URI" content="rzahwex9rx.htm" />
|
|
<meta name="DC.Relation" scheme="URI" content="rzahwoneco.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="rzahwdat-datco" />
|
|
<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>Thread-specific data</title>
|
|
</head>
|
|
<body id="rzahwdat-datco"><a name="rzahwdat-datco"><!-- --></a>
|
|
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
|
|
<h1 class="topictitle1">Thread-specific data</h1>
|
|
<div><p>Typical applications that are not threaded use global storage.</p>
|
|
<div class="section"><p>When changing the application or application services to run in
|
|
a multithreaded application, you must use a synchronization technique to protect
|
|
global storage from being changed by multiple threads at the same time. Thread-specific
|
|
data allows a thread to maintain its own global storage that is hidden from
|
|
the other threads. </p>
|
|
</div>
|
|
<div class="section"><p>Due to the design of the application, threads might not function
|
|
correctly if they share the global storage of the application. If eliminating
|
|
the global storage is not feasible, you should consider using thread-specific
|
|
data. </p>
|
|
</div>
|
|
<div class="section"><p>Consider the example of a server that stores information about
|
|
the client and the current transaction in global storage. This server is never
|
|
able to share the client information in a multithreaded environment without
|
|
significant redesign. The application can instead pass the client information
|
|
from function to function instead of using the global client information.</p>
|
|
</div>
|
|
<div class="section"><p>However, the application can maintain the client
|
|
and transaction information in thread-specific data more easily than it can
|
|
be modified to eliminate the use of global storage. When each new thread is
|
|
created, the thread uses a global identifier (or key) to create and store
|
|
its thread-specific data. Each client (thread) then has unique
|
|
but global client data.</p>
|
|
</div>
|
|
<div class="section"><p>In addition, some API sets provide a way for the system to automatically
|
|
call a <dfn class="term">data destructor</dfn> function that cleans up the thread-specific
|
|
data when a thread ends.</p>
|
|
</div>
|
|
</div>
|
|
<div>
|
|
<ul class="ullinks">
|
|
<li class="ulchildlink"><strong><a href="rzahwe21rx.htm">Example: Thread-specific data in Pthread programs</a></strong><br />
|
|
This example shows a Pthread program creating thread-specific data.</li>
|
|
<li class="ulchildlink"><strong><a href="rzahwex9rx.htm">Example: Thread-specific data in Java programs</a></strong><br />
|
|
This example shows a Java™ program creating thread-specific data.
|
|
Because a Java™ thread is created on an object, the use of thread-specific
|
|
data is transparent. Java™ is a language that performs garbage
|
|
collection. Note the lack of data destructors or other cleanup action.</li>
|
|
</ul>
|
|
|
|
<div class="familylinks">
|
|
<div class="parentlink"><strong>Parent topic:</strong> <a href="rzahwmulco.htm" title="If you are going to write multithreaded applications or server applications for i5/OS, you should be familiar with several techniques.">Multithreaded programming techniques</a></div>
|
|
</div>
|
|
<div class="relconcepts"><strong>Related concepts</strong><br />
|
|
<div><a href="rzahwoneco.htm" title="At times, you might want to defer the initialization of resources until a thread requires them. However, your application might require that multiple threads use a certain resource, which requires you to initialize the resource only once in a threadsafe way.">One-time initialization and thread safety</a></div>
|
|
</div>
|
|
</div>
|
|
</body>
|
|
</html> |