<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:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Word 14 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:Helvetica;
        panose-1:2 11 6 4 2 2 2 2 2 4;}
@font-face
        {font-family:\5B8B\4F53;
        panose-1:2 1 6 0 3 1 1 1 1 1;}
@font-face
        {font-family:\5B8B\4F53;
        panose-1:2 1 6 0 3 1 1 1 1 1;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Consolas;
        panose-1:2 11 6 9 2 2 4 3 2 4;}
@font-face
        {font-family:"\@\5B8B\4F53";
        panose-1:2 1 6 0 3 1 1 1 1 1;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        text-align:justify;
        text-justify:inter-ideograph;
        font-size:10.5pt;
        font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
p
        {mso-style-priority:99;
        mso-margin-top-alt:auto;
        margin-right:0cm;
        mso-margin-bottom-alt:auto;
        margin-left:0cm;
        font-size:12.0pt;
        font-family:\5B8B\4F53;}
code
        {mso-style-priority:99;
        font-family:Consolas;}
pre
        {mso-style-priority:99;
        mso-style-link:"HTML Preformatted Char";
        margin:0cm;
        margin-bottom:.0001pt;
        font-size:9.0pt;
        font-family:Consolas;}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:"Calibri","sans-serif";
        color:windowtext;}
span.HTMLPreformattedChar
        {mso-style-name:"HTML Preformatted Char";
        mso-style-priority:99;
        mso-style-link:"HTML Preformatted";
        font-family:Consolas;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri","sans-serif";}
/* Page Definitions */
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:72.0pt 90.0pt 72.0pt 90.0pt;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="ZH-CN" link="blue" vlink="purple" style="text-justify-trim:punctuation">
<div class="WordSection1">
<p class="MsoNormal" align="left" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;text-align:left">
<span lang="EN" style="font-family:"Helvetica","sans-serif";color:#333333">Hi, all<o:p></o:p></span></p>
<p class="MsoNormal" align="left" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;text-align:left;text-indent:21.0pt">
<span lang="EN" style="font-family:"Helvetica","sans-serif";color:#333333">when i read the src code of jemalloc of redis, i'm confused for below code in malloc_init_hard() function. do you know what's mean of IS_INITIALIZER, it said that it for: this thread
 is the initializing thread, and it is recursively allocating. what's the mean of the sentence? could you take an example for it? another question is if one thread is initializing, and this thread will wait for init_lock, after that thread finish the initializing.
 then the malloc_initialized will be set to true. then this thread will return false. but malloc_init_hard in invoked by je_malloc, so for this thread the je_malloc will be return false? and then allocated fail???? thanks for your time.<o:p></o:p></span></p>
<p class="MsoNormal" align="left" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;text-align:left">
<span lang="EN" style="font-family:"Helvetica","sans-serif";color:#333333">static bool<br>
malloc_init_hard(void)<br>
{<br>
arena_t *init_arenas[1];<br>
malloc_mutex_lock(&init_lock);<br>
if (malloc_initialized || IS_INITIALIZER) { <br>
* Another thread initialized the allocator before this one<br>
* acquired init_lock, or this thread is the initializing<br>
* thread, and it is recursively allocating.<br>
*/<br>
malloc_mutex_unlock(&init_lock);<br>
return (false);<br>
}<o:p></o:p></span></p>
<p class="MsoNormal" align="left" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;text-align:left">
<span lang="EN" style="font-family:"Helvetica","sans-serif";color:#333333">void *<br>
je_malloc(size_t size)<br>
{<br>
void *ret;<br>
size_t usize JEMALLOC_CC_SILENCE_INIT(0);<br>
prof_thr_cnt_t *cnt JEMALLOC_CC_SILENCE_INIT(NULL);<o:p></o:p></span></p>
<p class="MsoNormal" align="left" style="text-align:left"><span lang="EN" style="font-size:9.0pt;font-family:Consolas;color:#333333">if (malloc_init()) {<o:p></o:p></span></p>
<p class="MsoNormal" align="left" style="text-align:left"><span lang="EN" style="font-size:9.0pt;font-family:Consolas;color:#333333">    ret = NULL;<o:p></o:p></span></p>
<p class="MsoNormal" align="left" style="text-align:left"><span lang="EN" style="font-size:9.0pt;font-family:Consolas;color:#333333">    goto label_oom;<o:p></o:p></span></p>
<p class="MsoNormal" align="left" style="text-align:left"><span lang="EN" style="font-size:9.0pt;font-family:Consolas;color:#333333">}<o:p></o:p></span></p>
<p class="MsoNormal" align="left" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;text-align:left">
<span lang="EN" style="font-family:"Helvetica","sans-serif";color:#333333">label_oom:<br>
if (ret == NULL) {<br>
if (config_xmalloc && opt_xmalloc) {<br>
malloc_write(": Error in malloc(): "<br>
"out of memory\n");<br>
abort();<br>
}<br>
set_errno(ENOMEM);<br>
}<br>
if (config_prof && opt_prof && ret != NULL)<br>
prof_malloc(ret, usize, cnt);<br>
if (config_stats && ret != NULL) {<br>
assert(usize == isalloc(ret, config_prof));<br>
thread_allocated_tsd_get()->allocated += usize;<br>
}<br>
UTRACE(0, size, ret);<br>
JEMALLOC_VALGRIND_MALLOC(ret != NULL, ret, usize, false);<br>
return (ret);<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
</div>
</body>
</html>