<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Black on Medium]]></title>
        <description><![CDATA[Stories by Black on Medium]]></description>
        <link>https://medium.com/@xiaoheijw?source=rss-ccdcd214f3a8------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*t6JTLuIsGv961trM.jpg</url>
            <title>Stories by Black on Medium</title>
            <link>https://medium.com/@xiaoheijw?source=rss-ccdcd214f3a8------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 09:19:09 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@xiaoheijw/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[阻塞，非阻塞，同步，异步的区别]]></title>
            <link>https://medium.com/@xiaoheijw/%E9%98%BB%E5%A1%9E-%E9%9D%9E%E9%98%BB%E5%A1%9E-%E5%90%8C%E6%AD%A5-%E5%BC%82%E6%AD%A5%E7%9A%84%E5%8C%BA%E5%88%AB-97e65ea450ef?source=rss-ccdcd214f3a8------2</link>
            <guid isPermaLink="false">https://medium.com/p/97e65ea450ef</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[概念]]></category>
            <dc:creator><![CDATA[Black]]></dc:creator>
            <pubDate>Tue, 01 May 2018 15:37:34 GMT</pubDate>
            <atom:updated>2018-05-01T15:38:56.059Z</atom:updated>
            <content:encoded><![CDATA[<p>1，<strong><em>同步与异步</em></strong>：同步与异步关注的是<strong>消息通信机制 </strong>(synchronous communication/ asynchronous communication)，相对于请求的发起者，是否需要等到请求的结果（同步），还是请求完毕的时候，以某种方式通知请求发起者（异步）。</p><p>所谓同步，就是在发出一个*调用*时，在没有得到结果之前，该*调用*就不返回。但是一旦调用返回，就得到返回值了。<br>换句话说，就是由*调用者*主动等待这个*调用*的结果。</p><p>而异步则是相反，<strong>*调用*在发出之后，这个调用就直接返回了，所以没有返回结果</strong>。换句话说，当一个异步过程调用发出后，调用者不会立刻得到结果。而是在*调用*发出后，*被调用者*通过状态、通知来通知调用者，或通过回调函数处理这个调用。</p><p>举个通俗的例子：<br>你打电话问书店老板有没有《分布式系统》这本书，如果是同步通信机制，书店老板会说，你稍等，”我查一下”，然后开始查啊查，等查好了（可能是5秒，也可能是一天）告诉你结果（返回结果）。<br>而异步通信机制，书店老板直接告诉你我查一下啊，查好了打电话给你，然后直接挂电话了（不返回结果）。然后查好了，他会主动打电话给你。在这里老板通过“回电”这种方式来回调。</p><p>2，<strong><em>阻塞与非阻塞</em></strong></p><p>请求的受理者（服务器，程序）在处理某个请求的状态，</p><p>阻塞和非阻塞关注的是程序在等待调用结果（消息，返回值）时的状态.</p><p>阻塞调用是指调用结果返回之前，当前线程会被挂起。调用线程只有在得到结果之后才会返回。<br>非阻塞调用指在不能立刻得到结果之前，该调用不会阻塞当前线程。</p><p>3，<strong>协程</strong></p><p>误解，认为有了协程，就可以用同步程序的方式，写出异步的程序，原先同步的程序和第三方库，也会自动变成异步的。为什么说这是个误解呢，因为要写出有异步效果的程序，只有协程是不够的，还需要有<strong>底层IO</strong>的支持。在发生IO时，要将IO操作交给异步实现去执行，并让渡出协程的执行权，由调度去调度执行其他协程。 天生支持协程(或协程的类似物)的lua, stackless-python, golang等之外</p><p><strong>关于Python</strong></p><p>Python的IO实现虽然也没有对协程做处理，但是Python这样的动态语言，可以使用monkey patch的方式替换系统的IO实现。gevent就是这种做法，这也是使用gevent的greenlet的时候，一般必须要在使用前做monkey patch的原因</p><p><strong>关于goroutine</strong></p><p>goroutine的实现并不完全是传统意义上的协程。在协程阻塞的时候(cpu计算或者文件IO等)，多个goroutine会变成多线程的方式执行。golang1.2之后还有类似erlang reduction的机制，来改善goroutine调度的公平性。这个机制只有在函数调用等场合下才会生效，所以效果还比较有限</p><p>参考链接： 怎样理解阻塞非阻塞与同步异步的区别？ — 严肃的回答 — 知乎 <a href="https://www.zhihu.com/question/19732473/answer/20851256">https://www.zhihu.com/question/19732473/answer/20851256</a></p><p><a href="http://blog.p2hp.com/archives/2277">http://blog.p2hp.com/archives/2277</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=97e65ea450ef" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[问题：输入某二叉树的前序遍历和中序遍历的结果，请重建出该二叉树，…]]></title>
            <link>https://medium.com/@xiaoheijw/%E9%97%AE%E9%A2%98-%E8%BE%93%E5%85%A5%E6%9F%90%E4%BA%8C%E5%8F%89%E6%A0%91%E7%9A%84%E5%89%8D%E5%BA%8F%E9%81%8D%E5%8E%86%E5%92%8C%E4%B8%AD%E5%BA%8F%E9%81%8D%E5%8E%86%E7%9A%84%E7%BB%93%E6%9E%9C-%E8%AF%B7%E9%87%8D%E5%BB%BA%E5%87%BA%E8%AF%A5%E4%BA%8C%E5%8F%89%E6%A0%91-8ad0d980518f?source=rss-ccdcd214f3a8------2</link>
            <guid isPermaLink="false">https://medium.com/p/8ad0d980518f</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[数据结构]]></category>
            <dc:creator><![CDATA[Black]]></dc:creator>
            <pubDate>Mon, 30 Apr 2018 08:55:54 GMT</pubDate>
            <atom:updated>2018-04-30T08:55:54.648Z</atom:updated>
            <content:encoded><![CDATA[<p>问题：输入某二叉树的前序遍历和中序遍历的结果，请重建出该二叉树， 假设输入的前序遍历和中序遍历的结果中都不含重复的数字。例如输入前序遍历序列{1,2,4,7,3,5,6,8}和中序遍历序列{4,7,2,1,5,3,8,6}，则重建二叉树并返回。</p><pre>class TreeNode:<br>    def __init__(self,x):<br>        self.val = x<br>        self.left = None<br>        self.right = None</pre><pre>class Solution:<br>    def reConstructBinaryTree(self,pre,tin):<br>        if not pre or not tin:<br>           return None<br>        root = TreeNode(pre[0])<br>        i = tin.index(root.val)<br>        root.left = self.reConstructBinartTree(pre[1:i+1],tin[:i])<br>        root.right = self.reConstructBinartTree(pre[i+1:],tin[i+1])<br>        return root</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8ad0d980518f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[问题：输入一个链表，从尾到头打印链表每个节点的值。]]></title>
            <link>https://medium.com/@xiaoheijw/%E9%97%AE%E9%A2%98-%E8%BE%93%E5%85%A5%E4%B8%80%E4%B8%AA%E9%93%BE%E8%A1%A8-%E4%BB%8E%E5%B0%BE%E5%88%B0%E5%A4%B4%E6%89%93%E5%8D%B0%E9%93%BE%E8%A1%A8%E6%AF%8F%E4%B8%AA%E8%8A%82%E7%82%B9%E7%9A%84%E5%80%BC-fb0aa73905d?source=rss-ccdcd214f3a8------2</link>
            <guid isPermaLink="false">https://medium.com/p/fb0aa73905d</guid>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Black]]></dc:creator>
            <pubDate>Mon, 30 Apr 2018 07:11:28 GMT</pubDate>
            <atom:updated>2018-04-30T07:11:28.588Z</atom:updated>
            <content:encoded><![CDATA[<p>问题：输入一个链表，从尾到头打印链表每个节点的值。</p><pre>class listNode:<br>    def __init__(self,x):<br>         self.val = x<br>         self.next = None<br></pre><p>分析：链表的遍历顺序是从头到尾，可输出的顺序却是从尾到头，也就是说第一个遍历的节点最后一个输出，而最后一个遍历的节点却是第一个输出，这就是典型的’后进先出”，可以用栈实现这种顺序</p><pre>def print_list_from_tail_to_head(listNode):<br>    stack = []<br>    while listNode:<br>        stack.append(listNode.val)<br>        listNode = listNode.next<br>    return stack[::-1]</pre><p>既然用栈来实现这个函数，而递归在本质上就是一个栈结构，下面是递归版本</p><pre>def print_list_from_tail_to_head(listNode):<br>    if listNode:<br>        print_list_from_tail_to_head(listNode.next)<br>        print(listNode.val)</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fb0aa73905d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Ipfs搭建]]></title>
            <link>https://medium.com/@xiaoheijw/ipfs%E6%90%AD%E5%BB%BA-1e67dd2fc7e4?source=rss-ccdcd214f3a8------2</link>
            <guid isPermaLink="false">https://medium.com/p/1e67dd2fc7e4</guid>
            <category><![CDATA[blockchain]]></category>
            <dc:creator><![CDATA[Black]]></dc:creator>
            <pubDate>Wed, 14 Mar 2018 01:56:18 GMT</pubDate>
            <atom:updated>2018-03-14T01:56:18.242Z</atom:updated>
            <content:encoded><![CDATA[<p>1,下载ipfs</p><p><a href="https://dist.ipfs.io/#go-ipfs">https://dist.ipfs.io/#go-ipfs</a></p><pre>tar -xvf ipfs….tar.gz</pre><pre>cd ipfs</pre><pre>sudo ./install sh</pre><p>2,创建ipfs节点</p><pre>ipfs init</pre><pre>cd  ~/.ipfs</pre><pre>ipfs daemon #启动节点，会自动上传节点的hash，默认加入全球网络</pre><p>3,跨域资源共享 CORS配置</p><pre>$ ipfs config --json API.HTTPHeaders.Access-Control-Allow-Methods &#39;[&quot;PUT&quot;, &quot;GET&quot;, &quot;POST&quot;, &quot;OPTIONS&quot;]&#39; <br>$ ipfs config --json API.HTTPHeaders.Access-Control-Allow-Origin &#39;[&quot;*&quot;]&#39; <br>$ ipfs config --json API.HTTPHeaders.Access-Control-Allow-Credentials &#39;[&quot;true&quot;]&#39; <br>$ ipfs config --json API.HTTPHeaders.Access-Control-Allow-Headers &#39;[&quot;Authorization&quot;]&#39; $ ipfs config --json API.HTTPHeaders.Access-Control-Expose-Headers &#39;[&quot;Location&quot;]&#39;</pre><p>4,修改配置</p><pre>vi ~/.ipfs/config<br>127.0.0.1 修改为0.0.0.0<br>就可以通过ip访问</pre><p>5,私有节点搭建</p><p>5.1，生成swarm key</p><pre>pip install piskg<br>piskg &gt; ~/.ipfs/swarm.key<br> ipfs bootstrap rm --all<br>ipfs bootstrap add /ipfs/nodehash<br>ipfs daemon</pre><p>参考链接</p><p><a href="https://mp.weixin.qq.com/s/PwG4dAjj0ewuGeCbt1Av3A##">https://mp.weixin.qq.com/s/PwG4dAjj0ewuGeCbt1Av3A##</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1e67dd2fc7e4" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>