diff options
| author | muqiuhan <[email protected]> | 2024-08-02 03:27:42 +0000 |
|---|---|---|
| committer | muqiuhan <[email protected]> | 2024-08-02 03:27:42 +0000 |
| commit | 41537d9d09b52834c603101c4111955f6f55ece7 (patch) | |
| tree | 357ecd0a9f5789e4a538789632a644387402cac4 /search.xml | |
| parent | 13c421ac7f9b895930b0ed8207ca114b1d91dbc2 (diff) | |
| download | blog-41537d9d09b52834c603101c4111955f6f55ece7.tar.gz | |
deploy: 38bdfa3137383f8dc650517d3cbfb26997cd771a
Diffstat (limited to 'search.xml')
| -rw-r--r-- | search.xml | 64 |
1 files changed, 39 insertions, 25 deletions
@@ -953,6 +953,31 @@ </tags> </entry> <entry> + <title>caml_release_runtime_system导致的死锁问题</title> + <url>/2023/06/28/caml-release-runtime-system%E5%AF%BC%E8%87%B4%E7%9A%84%E6%AD%BB%E9%94%81%E9%97%AE%E9%A2%98/</url> + <content><![CDATA[<p>给出一个<code>test.ml</code>:</p> +<figure class="highlight ocaml"><table><tr><td class="code"><pre><span class="line"><span class="type">Printf</span>.eprintf <span class="string">"hello from OCaml\n%!"</span></span><br></pre></td></tr></table></figure> + +<p>和<code>test-ocaml-5.c</code>:</p> +<figure class="highlight c"><table><tr><td class="code"><pre><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string"><stdio.h></span></span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string"><stdlib.h></span></span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string"><caml/misc.h></span></span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string"><caml/callback.h></span></span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string"><caml/threads.h></span></span></span><br><span class="line"></span><br><span class="line"><span class="type">int</span></span><br><span class="line"><span class="title function_">main</span> <span class="params">(<span class="type">int</span> argc, <span class="type">char</span> *argv[])</span></span><br><span class="line"> {</span><br><span class="line"> <span class="built_in">fprintf</span> (<span class="built_in">stderr</span>, <span class="string">"starting up ...\n"</span>);</span><br><span class="line"> caml_startup (argv);</span><br><span class="line"> <span class="built_in">fprintf</span> (<span class="built_in">stderr</span>, <span class="string">"acquiring ...\n"</span>);</span><br><span class="line"> caml_acquire_runtime_system ();</span><br><span class="line"> <span class="built_in">fprintf</span> (<span class="built_in">stderr</span>, <span class="string">"acquired\n"</span>);</span><br><span class="line"> <span class="comment">// here is where I would be calling an OCaml callback</span></span><br><span class="line"> <span class="comment">// omitted for simplicity</span></span><br><span class="line"> caml_release_runtime_system ();</span><br><span class="line"> <span class="built_in">exit</span> (<span class="number">0</span>);</span><br><span class="line"> }</span><br></pre></td></tr></table></figure> + +<p>然后用OCaml5的ocaml native compiler编译一下(这里我用的是<code>ocaml-variants.5.0.0+options</code>):<br><code>ocamlopt -g test-ocaml-5.c test.ml -o test-ocaml-5</code></p> +<p>运行<code>test-ocaml-5</code> 会出现:</p> +<figure class="highlight plaintext"><table><tr><td class="code"><pre><span class="line">starting up ...</span><br><span class="line">hello from OCaml</span><br><span class="line">acquiring ...</span><br><span class="line">Fatal error: Fatal error during lock: Resource deadlock avoided</span><br><span class="line"></span><br><span class="line">[1] 8998 IOT instruction (core dumped) ./test-ocaml-5</span><br></pre></td></tr></table></figure> + +<p>这里我尝试了一下 4.14.0 和 4.14.1 , 都没有出现这个情况,而如果用<code>threads</code>编译的话:<br><code>ocamlopt -g -I +unix unix.cmxa -I +threads threads.cmxa test-ocaml-5.c test.ml -o test-ocaml-5</code></p> +<p>无论在5.0还是4.14.x,都会挂起。</p> +<p>出现这个问题的一个可能原因是,在<code>test-ocaml-5.c</code>中,我在开头调用了<code>caml_startup()</code>,这会让当前线程获取锁,而<code>caml_acquire_runtime_system()</code>会再次获取它,<code>caml_acquire_runtime_system()</code> 应该在<code>caml_release_runtime_system()</code>之后调用:</p> +<figure class="highlight ocaml"><table><tr><td class="code"><pre><span class="line"><span class="built_in">int</span></span><br><span class="line">main (<span class="built_in">int</span> argc, <span class="built_in">char</span> *argv<span class="literal">[]</span>)</span><br><span class="line"> {</span><br><span class="line"> fprintf (stderr, <span class="string">"starting up ...\n"</span>);</span><br><span class="line"> caml_startup (argv);</span><br><span class="line"> fprintf (stderr, <span class="string">"acquiring ...\n"</span>);</span><br><span class="line"> caml_release_runtime_system <span class="literal">()</span>;</span><br><span class="line"> caml_acquire_runtime_system <span class="literal">()</span>;</span><br><span class="line"> fprintf (stderr, <span class="string">"acquired\n"</span>);</span><br><span class="line"> exit (<span class="number">0</span>);</span><br><span class="line"> }</span><br></pre></td></tr></table></figure> + +<p>运行结果为:</p> +<figure class="highlight plaintext"><table><tr><td class="code"><pre><span class="line">starting up ...</span><br><span class="line">hello from OCaml</span><br><span class="line">acquiring ...</span><br><span class="line">acquired</span><br></pre></td></tr></table></figure>]]></content> + <tags> + <tag>Technique</tag> + <tag>OCaml</tag> + </tags> + </entry> + <entry> <title>WiscKey: Separating Keys from Values in SSD-conscious Storage</title> <url>/2023/07/21/WiscKey-Separating-Keys-from-Values-in-SSD-conscious-Storage/</url> <content><![CDATA[<p>We present WiscKey, a persistent LSM-tree-based key-value store with a performance-oriented data layoutthat separates keys from values to minimize I/O amplifi-cation. The design of WiscKey is highly SSD optimized, leveraging both the sequential and random performance characteristics of the device.</p> @@ -992,31 +1017,6 @@ </tags> </entry> <entry> - <title>caml_release_runtime_system导致的死锁问题</title> - <url>/2023/06/28/caml-release-runtime-system%E5%AF%BC%E8%87%B4%E7%9A%84%E6%AD%BB%E9%94%81%E9%97%AE%E9%A2%98/</url> - <content><![CDATA[<p>给出一个<code>test.ml</code>:</p> -<figure class="highlight ocaml"><table><tr><td class="code"><pre><span class="line"><span class="type">Printf</span>.eprintf <span class="string">"hello from OCaml\n%!"</span></span><br></pre></td></tr></table></figure> - -<p>和<code>test-ocaml-5.c</code>:</p> -<figure class="highlight c"><table><tr><td class="code"><pre><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string"><stdio.h></span></span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string"><stdlib.h></span></span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string"><caml/misc.h></span></span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string"><caml/callback.h></span></span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string"><caml/threads.h></span></span></span><br><span class="line"></span><br><span class="line"><span class="type">int</span></span><br><span class="line"><span class="title function_">main</span> <span class="params">(<span class="type">int</span> argc, <span class="type">char</span> *argv[])</span></span><br><span class="line"> {</span><br><span class="line"> <span class="built_in">fprintf</span> (<span class="built_in">stderr</span>, <span class="string">"starting up ...\n"</span>);</span><br><span class="line"> caml_startup (argv);</span><br><span class="line"> <span class="built_in">fprintf</span> (<span class="built_in">stderr</span>, <span class="string">"acquiring ...\n"</span>);</span><br><span class="line"> caml_acquire_runtime_system ();</span><br><span class="line"> <span class="built_in">fprintf</span> (<span class="built_in">stderr</span>, <span class="string">"acquired\n"</span>);</span><br><span class="line"> <span class="comment">// here is where I would be calling an OCaml callback</span></span><br><span class="line"> <span class="comment">// omitted for simplicity</span></span><br><span class="line"> caml_release_runtime_system ();</span><br><span class="line"> <span class="built_in">exit</span> (<span class="number">0</span>);</span><br><span class="line"> }</span><br></pre></td></tr></table></figure> - -<p>然后用OCaml5的ocaml native compiler编译一下(这里我用的是<code>ocaml-variants.5.0.0+options</code>):<br><code>ocamlopt -g test-ocaml-5.c test.ml -o test-ocaml-5</code></p> -<p>运行<code>test-ocaml-5</code> 会出现:</p> -<figure class="highlight plaintext"><table><tr><td class="code"><pre><span class="line">starting up ...</span><br><span class="line">hello from OCaml</span><br><span class="line">acquiring ...</span><br><span class="line">Fatal error: Fatal error during lock: Resource deadlock avoided</span><br><span class="line"></span><br><span class="line">[1] 8998 IOT instruction (core dumped) ./test-ocaml-5</span><br></pre></td></tr></table></figure> - -<p>这里我尝试了一下 4.14.0 和 4.14.1 , 都没有出现这个情况,而如果用<code>threads</code>编译的话:<br><code>ocamlopt -g -I +unix unix.cmxa -I +threads threads.cmxa test-ocaml-5.c test.ml -o test-ocaml-5</code></p> -<p>无论在5.0还是4.14.x,都会挂起。</p> -<p>出现这个问题的一个可能原因是,在<code>test-ocaml-5.c</code>中,我在开头调用了<code>caml_startup()</code>,这会让当前线程获取锁,而<code>caml_acquire_runtime_system()</code>会再次获取它,<code>caml_acquire_runtime_system()</code> 应该在<code>caml_release_runtime_system()</code>之后调用:</p> -<figure class="highlight ocaml"><table><tr><td class="code"><pre><span class="line"><span class="built_in">int</span></span><br><span class="line">main (<span class="built_in">int</span> argc, <span class="built_in">char</span> *argv<span class="literal">[]</span>)</span><br><span class="line"> {</span><br><span class="line"> fprintf (stderr, <span class="string">"starting up ...\n"</span>);</span><br><span class="line"> caml_startup (argv);</span><br><span class="line"> fprintf (stderr, <span class="string">"acquiring ...\n"</span>);</span><br><span class="line"> caml_release_runtime_system <span class="literal">()</span>;</span><br><span class="line"> caml_acquire_runtime_system <span class="literal">()</span>;</span><br><span class="line"> fprintf (stderr, <span class="string">"acquired\n"</span>);</span><br><span class="line"> exit (<span class="number">0</span>);</span><br><span class="line"> }</span><br></pre></td></tr></table></figure> - -<p>运行结果为:</p> -<figure class="highlight plaintext"><table><tr><td class="code"><pre><span class="line">starting up ...</span><br><span class="line">hello from OCaml</span><br><span class="line">acquiring ...</span><br><span class="line">acquired</span><br></pre></td></tr></table></figure>]]></content> - <tags> - <tag>Technique</tag> - <tag>OCaml</tag> - </tags> - </entry> - <entry> <title>使用 [@poll error] 实现线程安全的数据结构</title> <url>/2023/08/15/poll-error-attribute-in-OCaml/</url> <content><![CDATA[<p>OCaml的标准库提供了许多mutable的数据结构,比如Hashtbl, Queue, Stack之类的,但是这些数据结构都不是线程安全的。在 OCaml 4 和 OCaml 5 中,单个Domain中一次只能运行一个线程。换句话说,单个Domain中的线程仍然不会并行运行,除非在不同所的Domain中。</p> @@ -1313,6 +1313,20 @@ </categories> </entry> <entry> + <title>二〇二四年八月一日</title> + <url>/2024/08/02/%E4%BA%8C%E3%80%87%E4%BA%8C%E5%9B%9B%E5%B9%B4%E5%85%AB%E6%9C%88%E4%B8%80%E6%97%A5/</url> + <content><![CDATA[<p>我们之所以看到宇宙是这个样子,是因为如果它不是这样的话,我们就不会在这里去观察它。</p> +<p>如果我们仔细思考关于可能存在的宇宙的巨大迷宫,<br>我们就会发现大部分宇宙没有适合生命生产的条件,<br>哪怕任何与已知生命相近的东西,<br>以世人所熟悉的物理剧变来说,<br>这一点再清晰不过了,<br>If our universe didn’t conform to the rules it does,<br>Life as we know it would not exist,<br>哪怕是不那么激烈的物理变化也会干扰星球的形成,<br>比如,<br>扰乱他们作为宇宙熔炉的能力,<br>即合成维系生命的复杂的原子,<br>如碳原子,氧原子,<br>而碳氧原子通常是因超新星爆炸喷涌而出,<br>并散布在整个宇宙中的,<br>鉴于生命高度依赖于物理的各个细支,<br>如果我们现在发问,比如,<br>为什么自然中的各种力和粒子有我们观察到的各种特定属性组合,<br>一个合理的答案,<br>越过所有的可能性闪现出来,<br>这些特点各有不同,<br>属性也各有不同,<br>What’s special about the particular combination of particle and force properties we observe,<br>Is that clearly they allow life to form,<br>而生命,尤其是有智慧的生命,<br>是得以思考宇宙有如此属性,<br>的先决条件,<br>简单来说,<br>事物生来便是如此,<br>Because if they weren’t,<br>We wouldnt be here to notice,</p> +<p>If we weren’t here,<br>There’d be no one to see。</p> +<p>政治和工业的缺失,<br>诸神危机,<br>短浅目光,<br>停止怀疑其真伪,<br>你的敬畏感,<br>你的惊奇感,<br>面对这一切时丝毫无损,<br>也许适时的,<br>会有人听到这段残声,<br>这段无主题的演讲。</p> +<hr> +<p>阿公烧烟成老瘾,<br>阿公饮酒会面红,<br>他说日子要开心,<br>他说人生要尽兴。</p> +]]></content> + <categories> + <category>gallery</category> + </categories> + </entry> + <entry> <title>二〇二四年六月二十七日</title> <url>/2024/06/27/%E4%BA%8C%E3%80%87%E4%BA%8C%E5%9B%9B%E5%B9%B4%E5%85%AD%E6%9C%88%E4%BA%8C%E5%8D%81%E4%B8%83%E6%97%A5/</url> <content><