wcslib (8.2.2)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
<meta name="generator" content="Doxygen 1.9.8"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>WCSLIB: Thread-safety</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr id="projectrow">
<td id="projectalign">
<div id="projectname">WCSLIB<span id="projectnumber"> 8.2.2</span>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.9.8 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */
var searchBox = new SearchBox("searchBox", "search/",'.html');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt MIT */
$(function() {
initMenu('',true,false,'search.php','Search');
$(document).ready(function() { init_search(); });
});
/* @license-end */
</script>
<div id="main-nav"></div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>
<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<div id="MSearchResults">
<div class="SRPage">
<div id="SRIndex">
<div id="SRResults"></div>
<div class="SRStatus" id="Loading">Loading...</div>
<div class="SRStatus" id="Searching">Searching...</div>
<div class="SRStatus" id="NoMatches">No Matches</div>
</div>
</div>
</div>
</div>
<div id="nav-path" class="navpath">
<ul>
<li class="navelem"><a class="el" href="index.html">WCSLIB 8.2.2 and PGSBOX 8.2.2</a></li> </ul>
</div>
</div><!-- top -->
<div><div class="header">
<div class="headertitle"><div class="title">Thread-safety</div></div>
</div><!--header-->
<div class="contents">
<div class="textblock"><p>Thanks to feedback and patches provided by Rodrigo Tobar Carrizo, as of release 5.18, WCSLIB is now completely thread-safe, with only a couple of minor provisos.</p>
<p>In particular, a number of new routines were introduced to preclude altering the global variables NPVMAX, NPSMAX, and NDPMAX, which determine how much memory to allocate for storing PVi_ma, PSi_ma, DPja, and DQia keyvalues: <a class="el" href="wcs_8h.html#aab11243b60b10065fc85347bb3efa912" title="Default constructor for the wcsprm struct.">wcsinit()</a>, <a class="el" href="lin_8h.html#afa85e4b255b144d2b806f51be0d36be2" title="Default constructor for the linprm struct.">lininit()</a>, <a class="el" href="lin_8h.html#ad5bc6ffb673b1c38105bdf2d8def5194" title="Assign a distortion to a linprm struct.">lindist()</a>, and <a class="el" href="dis_8h.html#a3e0e67bdd01c86eede779de63249c703" title="Default constructor for the disprm struct.">disinit()</a>. Specifically, these new routines are now used by various WCSLIB routines, such as the header parsers, which previously temporarily altered the global variables, thus posing a thread hazard.</p>
<p>In addition, the Flex scanners were made reentrant and consequently should now be thread-safe. This was achieved by rewriting them as thin wrappers (with the same API) over scanners that were modified (with changed API), as required to use Flex's "reentrant" option.</p>
<p>For complete thread-safety, please observe the following provisos:</p>
<ul>
<li><p class="startli">The low-level routines <a class="el" href="wcs_8h.html#a42b2578d76ace7ca6114d82b7ae46a89" title="Memory allocation for PVi_ma.">wcsnpv()</a>, <a class="el" href="wcs_8h.html#ae790c9ce6c9b7a4845cf1c3c97b1e97a" title="Memory allocation for PSi_ma.">wcsnps()</a>, and <a class="el" href="dis_8h.html#aa5486b870327544f7423ad2751fb4120" title="Memory allocation for DPja and DQia.">disndp()</a> are not thread-safe, but they are not used within WCSLIB itself other than to get (not set) the values of the global variables NPVMAX, NPSMAX, and NDPMAX.</p>
<p class="startli"><a class="el" href="wcs_8h.html#aab11243b60b10065fc85347bb3efa912" title="Default constructor for the wcsprm struct.">wcsinit()</a> and <a class="el" href="dis_8h.html#a3e0e67bdd01c86eede779de63249c703" title="Default constructor for the disprm struct.">disinit()</a> only do so to get default values if the relevant parameters are not provided as function arguments. Note that <a class="el" href="wcs_8h.html#a2afc8255fde0965dddaa374463666d45" title="Default constructor for the wcsprm struct.">wcsini()</a> invokes <a class="el" href="wcs_8h.html#aab11243b60b10065fc85347bb3efa912" title="Default constructor for the wcsprm struct.">wcsinit()</a> with defaults which cause this behavior, as does <a class="el" href="dis_8h.html#a8896e2a5330e55cd85da4a28ed6ee463" title="Default constructor for the disprm struct.">disini()</a> invoking <a class="el" href="dis_8h.html#a3e0e67bdd01c86eede779de63249c703" title="Default constructor for the disprm struct.">disinit()</a>.</p>
<p class="startli">The preset values of NPVMAX(=64), NPSMAX(=8), and NDPMAX(=256) are large enough to cover most practical cases. However, it may be desirable to tailor them to avoid allocating memory that remains unused. If so, and thread-safety is an issue, then use <a class="el" href="wcs_8h.html#aab11243b60b10065fc85347bb3efa912" title="Default constructor for the wcsprm struct.">wcsinit()</a> and <a class="el" href="dis_8h.html#a3e0e67bdd01c86eede779de63249c703" title="Default constructor for the disprm struct.">disinit()</a> instead with the relevant values specified. This is what WCSLIB routines, such as the header parsers <a class="el" href="wcshdr_8h.html#ac75623ee805ab7d43b0bba684c719a60" title="FITS WCS parser routine for image headers.">wcspih()</a> and <a class="el" href="wcshdr_8h.html#adc053d80a9c4da454a52eed34e123633" title="FITS WCS parser routine for binary table and image headers.">wcsbth()</a>, do to avoid wasting memory.</p>
</li>
<li><a class="el" href="wcserr_8h.html#a1691b8bd184d40ca6fda255be078fa53" title="Enable/disable error messaging.">wcserr_enable()</a> sets a static variable and so is not thread-safe. However, the error reporting facility is not intended to be used dynamically. If detailed error messages are required, enable wcserr when execution starts and don't change it.</li>
</ul>
<p>Note that diagnostic routines that print the contents of the various structs, namely <a class="el" href="cel_8h.html#adb2e4565f61a9de5fe278d9035850dc3" title="Print routine for the celprm struct.">celprt()</a>, <a class="el" href="dis_8h.html#aeee35e0d5183e74f20c64526d908886b" title="Print routine for the disprm struct.">disprt()</a>, <a class="el" href="lin_8h.html#a946005b038f5c584691630b5d39369e3" title="Print routine for the linprm struct.">linprt()</a>, <a class="el" href="prj_8h.html#a8785bdf33bdaa3d9d52fd51b621ec8d5" title="Print routine for the prjprm struct.">prjprt()</a>, <a class="el" href="spc_8h.html#a7304d0d00bcf9d2bad1f56ba6d8322ea" title="Print routine for the spcprm struct.">spcprt()</a>, <a class="el" href="tab_8h.html#a6b3768349e9a5e925aab24effddc584f" title="Print routine for the tabprm struct.">tabprt()</a>, <a class="el" href="wcs_8h.html#ab9aeb8cf1afb1bfb22e989580d90fca8" title="Print routine for the wcsprm struct.">wcsprt()</a>, and <a class="el" href="wcs_8h.html#a8fe5dcd9927240dc0348b850ee662367" title="Print error messages from a wcsprm struct.">wcsperr()</a> use printf() which is thread-safe by the POSIX requirement on <code>stdio</code>. However, this is only at the function level. Where multiple threads invoke these routines simultaneously their output is likely to be interleaved. </p>
</div></div><!-- contents -->
</div><!-- PageDoc -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated on Wed Nov 29 2023 19:09:57 for WCSLIB by <a href="https://www.doxygen.org/index.html"><img class="footer" src="doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.8
</small></address>
</body>
</html>