1<html lang="en"> 2<head> 3<title>__malloc_lock - Untitled</title> 4<meta http-equiv="Content-Type" content="text/html"> 5<meta name="description" content="Untitled"> 6<meta name="generator" content="makeinfo 4.13"> 7<link title="Top" rel="start" href="index.html#Top"> 8<link rel="up" href="Stdlib.html#Stdlib" title="Stdlib"> 9<link rel="prev" href="mallinfo.html#mallinfo" title="mallinfo"> 10<link rel="next" href="mbsrtowcs.html#mbsrtowcs" title="mbsrtowcs"> 11<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage"> 12<meta http-equiv="Content-Style-Type" content="text/css"> 13<style type="text/css"><!-- 14 pre.display { font-family:inherit } 15 pre.format { font-family:inherit } 16 pre.smalldisplay { font-family:inherit; font-size:smaller } 17 pre.smallformat { font-family:inherit; font-size:smaller } 18 pre.smallexample { font-size:smaller } 19 pre.smalllisp { font-size:smaller } 20 span.sc { font-variant:small-caps } 21 span.roman { font-family:serif; font-weight:normal; } 22 span.sansserif { font-family:sans-serif; font-weight:normal; } 23--></style> 24<link rel="stylesheet" type="text/css" href="../cs.css"> 25</head> 26<body> 27<div class="node"> 28<a name="__malloc_lock"></a> 29<a name="g_t_005f_005fmalloc_005flock"></a> 30<p> 31Next: <a rel="next" accesskey="n" href="mbsrtowcs.html#mbsrtowcs">mbsrtowcs</a>, 32Previous: <a rel="previous" accesskey="p" href="mallinfo.html#mallinfo">mallinfo</a>, 33Up: <a rel="up" accesskey="u" href="Stdlib.html#Stdlib">Stdlib</a> 34<hr> 35</div> 36 37<h3 class="section">2.25 <code>__malloc_lock</code>, <code>__malloc_unlock</code>—lock malloc pool</h3> 38 39<p><a name="index-g_t_005f_005fmalloc_005flock-55"></a><a name="index-g_t_005f_005fmalloc_005funlock-56"></a><strong>Synopsis</strong> 40<pre class="example"> #include <malloc.h> 41 void __malloc_lock (struct _reent *<var>reent</var>); 42 void __malloc_unlock (struct _reent *<var>reent</var>); 43 44</pre> 45 <p><strong>Description</strong><br> 46The <code>malloc</code> family of routines call these functions when they need to lock 47the memory pool. The version of these routines supplied in the library use 48the lock API defined in sys/lock.h. If multiple threads of execution can 49call <code>malloc</code>, or if <code>malloc</code> can be called reentrantly, then you need to 50define your own versions of these functions in order to safely lock the 51memory pool during a call. If you do not, the memory pool may become 52corrupted. 53 54 <p>A call to <code>malloc</code> may call <code>__malloc_lock</code> recursively; that is, 55the sequence of calls may go <code>__malloc_lock</code>, <code>__malloc_lock</code>, 56<code>__malloc_unlock</code>, <code>__malloc_unlock</code>. Any implementation of these 57routines must be careful to avoid causing a thread to wait for a lock 58that it already holds. 59 60 <p><br> 61 62 </body></html> 63 64