1999-08-16 21:50:52 +00:00
|
|
|
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
|
2000-01-15 02:00:06 +00:00
|
|
|
<html xmlns:v="urn:schemas-microsoft-com:vml"
|
|
|
|
xmlns:o="urn:schemas-microsoft-com:office:office"
|
|
|
|
xmlns:w="urn:schemas-microsoft-com:office:word"
|
|
|
|
xmlns="http://www.w3.org/TR/REC-html40">
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
<head>
|
2000-01-15 02:00:06 +00:00
|
|
|
<meta http-equiv=Content-Type content="text/html; charset=iso-8859-1">
|
|
|
|
<meta name=ProgId content=Word.Document>
|
|
|
|
<meta name=Generator content="Microsoft Word 9">
|
|
|
|
<meta name=Originator content="Microsoft Word 9">
|
|
|
|
<link rel=File-List href="./mutex_files/filelist.xml">
|
1999-08-16 21:50:52 +00:00
|
|
|
<title>Mutex Documentation</title>
|
2000-01-15 02:00:06 +00:00
|
|
|
<!--[if gte mso 9]><xml>
|
|
|
|
<o:DocumentProperties>
|
|
|
|
<o:Author>Helena Shih</o:Author>
|
|
|
|
<o:Template>Normal</o:Template>
|
|
|
|
<o:LastAuthor>Helena Shih</o:LastAuthor>
|
|
|
|
<o:Revision>2</o:Revision>
|
|
|
|
<o:TotalTime>0</o:TotalTime>
|
|
|
|
<o:Created>2000-01-15T02:23:00Z</o:Created>
|
|
|
|
<o:LastSaved>2000-01-15T02:23:00Z</o:LastSaved>
|
|
|
|
<o:Pages>2</o:Pages>
|
|
|
|
<o:Words>522</o:Words>
|
|
|
|
<o:Characters>2979</o:Characters>
|
|
|
|
<o:Company>IBM</o:Company>
|
|
|
|
<o:Lines>24</o:Lines>
|
|
|
|
<o:Paragraphs>5</o:Paragraphs>
|
|
|
|
<o:CharactersWithSpaces>3658</o:CharactersWithSpaces>
|
|
|
|
<o:Version>9.2720</o:Version>
|
|
|
|
</o:DocumentProperties>
|
|
|
|
</xml><![endif]-->
|
|
|
|
<style>
|
|
|
|
<!--
|
|
|
|
/* Font Definitions */
|
|
|
|
@font-face
|
|
|
|
{font-family:Wingdings;
|
|
|
|
panose-1:5 0 0 0 0 0 0 0 0 0;
|
|
|
|
mso-font-charset:2;
|
|
|
|
mso-generic-font-family:auto;
|
|
|
|
mso-font-pitch:variable;
|
|
|
|
mso-font-signature:0 268435456 0 0 -2147483648 0;}
|
|
|
|
/* Style Definitions */
|
|
|
|
p.MsoNormal, li.MsoNormal, div.MsoNormal
|
|
|
|
{mso-style-parent:"";
|
|
|
|
margin:0in;
|
|
|
|
margin-bottom:.0001pt;
|
|
|
|
mso-pagination:widow-orphan;
|
|
|
|
font-size:12.0pt;
|
|
|
|
font-family:"Times New Roman";
|
|
|
|
mso-fareast-font-family:"Times New Roman";}
|
|
|
|
p
|
|
|
|
{font-size:12.0pt;
|
|
|
|
font-family:"Times New Roman";
|
|
|
|
mso-fareast-font-family:"Times New Roman";}
|
|
|
|
@page Section1
|
|
|
|
{size:8.5in 11.0in;
|
|
|
|
margin:1.0in 1.25in 1.0in 1.25in;
|
|
|
|
mso-header-margin:.5in;
|
|
|
|
mso-footer-margin:.5in;
|
|
|
|
mso-paper-source:0;}
|
|
|
|
div.Section1
|
|
|
|
{page:Section1;}
|
|
|
|
/* List Definitions */
|
|
|
|
@list l0
|
|
|
|
{mso-list-id:1299845606;
|
|
|
|
mso-list-type:hybrid;
|
|
|
|
mso-list-template-ids:-1849547252 -302606876 -817858888 -819169718 -1866726332 223118424 -996776518 -314158042 -1140712398 101464222;}
|
|
|
|
@list l0:level1
|
|
|
|
{mso-level-number-format:bullet;
|
|
|
|
mso-level-text:\F0B7;
|
|
|
|
mso-level-tab-stop:.5in;
|
|
|
|
mso-level-number-position:left;
|
|
|
|
text-indent:-.25in;
|
|
|
|
mso-ansi-font-size:10.0pt;
|
|
|
|
font-family:Symbol;}
|
|
|
|
ol
|
|
|
|
{margin-bottom:0in;}
|
|
|
|
ul
|
|
|
|
{margin-bottom:0in;}
|
|
|
|
-->
|
|
|
|
</style>
|
|
|
|
<!--[if gte mso 9]><xml>
|
|
|
|
<o:shapedefaults v:ext="edit" spidmax="1027"/>
|
|
|
|
</xml><![endif]--><!--[if gte mso 9]><xml>
|
|
|
|
<o:shapelayout v:ext="edit">
|
|
|
|
<o:idmap v:ext="edit" data="1"/>
|
|
|
|
</o:shapelayout></xml><![endif]-->
|
1999-08-16 21:50:52 +00:00
|
|
|
</head>
|
|
|
|
|
2000-01-15 02:00:06 +00:00
|
|
|
<body bgcolor=white lang=EN-US style='tab-interval:.5in'>
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2000-01-15 02:00:06 +00:00
|
|
|
<div class=Section1>
|
|
|
|
|
2000-02-21 21:38:59 +00:00
|
|
|
<h1>International Components for Unicode Synchronization Issues</h1>
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
<h3>Introduction</h3>
|
|
|
|
|
2000-01-15 02:00:06 +00:00
|
|
|
<p>There are a number of functions in the IBM's Classes for Unicode that need
|
|
|
|
to access or allocate global or static data. For example, there is a global
|
|
|
|
cache of Collation rules, which ensures that we do not need to load collation
|
|
|
|
data from a file each time that a new Collator object is created. The first
|
|
|
|
time a given Collator is loaded it is stored in the cache, and subsequent
|
|
|
|
accesses are extremely fast. </p>
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
<p>In a single-threaded environment, this is all straightforward. However, in a
|
2000-01-15 02:00:06 +00:00
|
|
|
multithreaded application there are synchronization issues to deal with. For
|
|
|
|
example, the collation caching mechanism needs to be protected from
|
|
|
|
simultaneous access by multiple threads; otherwise there could be problems with
|
|
|
|
the data getting out of synch or with threads performing unnecessary work. </p>
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
<h3>Mutexes</h3>
|
|
|
|
|
2000-01-15 02:00:06 +00:00
|
|
|
<p>We prevent these problems by using a Mutex object. A Mutex is a
|
|
|
|
"mutually exclusive" lock. Before accessing data which might be used
|
|
|
|
by multiple threads, functions instantiate a Mutex object, which acquires the
|
|
|
|
exclusive lock. An other thread that tries to access the data at the same time
|
|
|
|
will also instantiate a Mutex, but the call will block until the first thread
|
|
|
|
has released its lock. </p>
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2000-01-15 02:00:06 +00:00
|
|
|
<p>To save space, we use one underlying mutex implementation object for the
|
|
|
|
entire application. An individual Mutex object simply acquires and releases the
|
|
|
|
lock on this this global object. Since the implemention of a mutex is highly
|
|
|
|
platform-dependent, developers who plan to use the International Classes for
|
|
|
|
Unicode in a multithreaded environment are required to create their own mutex
|
|
|
|
implementation object and register it with the system. </p>
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
<h3>Re-Entrancy</h3>
|
|
|
|
|
2000-01-15 02:00:06 +00:00
|
|
|
<p>Using a single, global lock object can, of course, cause reentrancy
|
|
|
|
problems. Deadlock could occur where the Mutex aquire is attempted twice within
|
|
|
|
the same thread before it is released. For example, Win32 critical sections are
|
|
|
|
reentrant, but our testing shows that some POSIX mutex implementations are not.
|
|
|
|
POSIX would require additional code, at a performance loss. </p>
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2000-01-15 02:00:06 +00:00
|
|
|
<p>To avoid these problems, the Mutex is only aquired during a pointer
|
|
|
|
assignment, where possible. In the few cases where this is not true, care is
|
|
|
|
taken to not call any other functions inside the mutex that could possibly
|
|
|
|
aquire the mutex. </p>
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2000-01-15 02:00:06 +00:00
|
|
|
<p>The result of this design principle is that the mutex may be aquired more
|
|
|
|
times than necessary, however time spent inside the mutex is then minimized. </p>
|
1999-08-16 21:50:52 +00:00
|
|
|
|
|
|
|
<p>Developers implementing the Mutex are not required to provide reentrant-safe
|
|
|
|
implementations. </p>
|
|
|
|
|
1999-10-28 18:06:45 +00:00
|
|
|
<h3>Using collators in multi-threaded environment</h3>
|
|
|
|
|
2000-01-15 02:00:06 +00:00
|
|
|
<p>Instances of Collator class are meant to be used on per thread basis.
|
|
|
|
Although it is possible to have multiple threads access one Collator there is
|
|
|
|
no guarante that such a construct will work, especially if number of threads
|
|
|
|
grows over 10. There are no limitations on number of threads if each thread
|
|
|
|
creates its own separate instance of Collator class.</p>
|
1999-10-28 18:06:45 +00:00
|
|
|
|
2000-01-15 02:00:06 +00:00
|
|
|
<p>Test results have shown that case with 50 threads accessing 1 collator fails
|
|
|
|
with a crash after 20 threads are reached. However, a test with 50 threads
|
|
|
|
creating separate instances works well.</p>
|
1999-10-28 18:06:45 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
<h3>Implementations</h3>
|
|
|
|
|
2000-01-15 02:00:06 +00:00
|
|
|
<p>On Win32 platforms, a reentrant mutex is most naturally implemented on top
|
|
|
|
of a Critical Section.<br>
|
1999-08-16 21:50:52 +00:00
|
|
|
On POSIX platforms, pthread_mutex provides an implementation. </p>
|
|
|
|
|
2000-01-15 02:00:06 +00:00
|
|
|
<p>The International Classes for Unicode are provided with reference
|
|
|
|
implementations for Win32 and POSIX. </p>
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2000-01-15 02:00:06 +00:00
|
|
|
<p><b>See also:</b> </p>
|
1999-08-16 21:50:52 +00:00
|
|
|
|
2000-01-15 02:00:06 +00:00
|
|
|
<ul type=disc>
|
|
|
|
<li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;
|
|
|
|
mso-list:l0 level1 lfo1;tab-stops:list .5in'><b>mutex.h </b>- Mutex API</li>
|
|
|
|
<li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;
|
|
|
|
mso-list:l0 level1 lfo1;tab-stops:list .5in'><b>muteximp.h</b> - The API's
|
|
|
|
and instructions for providing your own mutexes.</li>
|
|
|
|
<li class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;
|
|
|
|
mso-list:l0 level1 lfo1;tab-stops:list .5in'><b>mutex.cpp</b> - includes
|
|
|
|
reference implementations for Win32 and POSIX.</li>
|
1999-08-16 21:50:52 +00:00
|
|
|
</ul>
|
2000-01-15 02:00:06 +00:00
|
|
|
|
|
|
|
</div>
|
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
</body>
|
2000-01-15 02:00:06 +00:00
|
|
|
|
1999-08-16 21:50:52 +00:00
|
|
|
</html>
|