<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>编程小札 &#8211; CodeShell.io</title>
	<atom:link href="https://codeshell.io/feed" rel="self" type="application/rss+xml" />
	<link>https://codeshell.io</link>
	<description></description>
	<lastBuildDate>Fri, 15 Aug 2025 19:43:03 +0000</lastBuildDate>
	<language>zh-Hans</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.8.2</generator>

<image>
	<url>https://codeshell.io/wp-content/uploads/2020/06/cropped-code-32x32.png</url>
	<title>编程小札 &#8211; CodeShell.io</title>
	<link>https://codeshell.io</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Ubuntu22.04 安装 MySQL 5.7</title>
		<link>https://codeshell.io/archives/563</link>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Thu, 01 Feb 2024 15:17:21 +0000</pubDate>
				<category><![CDATA[MySQL]]></category>
		<guid isPermaLink="false">https://codeshell.io/?p=563</guid>

					<description><![CDATA[1 . 添加 MySQL 源 添加如下内容 更新 执行过程中可能会出现如下错误 执行如下命令即可，B7B3B788A8D3785C 根据实际情况替换 接着再重新...<p class="read-more"><a class="btn btn-default" href="https://codeshell.io/archives/563"> Read More<span class="screen-reader-text">  Read More</span></a></p>]]></description>
										<content:encoded><![CDATA[
<p class="has-medium-font-size">1 . 添加 MySQL 源</p>



<div class="wp-block-kevinbatdorf-code-block-pro" data-code-block-pro-font-family="" style="font-size:clamp(14px, .875rem, 21px);line-height:clamp(20px, 1.25rem, 30px);--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff"><svg xmlns="http://www.w3.org/2000/svg" width="54" height="14" viewBox="0 0 54 14"><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><circle cx="6" cy="6" r="6" fill="#FF5F56" stroke="#E0443E" stroke-width=".5"></circle><circle cx="26" cy="6" r="6" fill="#FFBD2E" stroke="#DEA123" stroke-width=".5"></circle><circle cx="46" cy="6" r="6" fill="#27C93F" stroke="#1AAB29" stroke-width=".5"></circle></g></svg></span><span role="button" tabindex="0" style="color:#d8dee9ff;display:none" aria-label="复制" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>sudo vim /etc/apt/sources.list.d/mysql.list</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki nord" style="background-color: #2e3440ff" tabindex="0"><code><span class="line"><span style="color: #88C0D0">sudo</span><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">vim</span><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">/etc/apt/sources.list.d/mysql.list</span></span></code></pre></div>



<p></p>



<p class="has-small-font-size">添加如下内容</p>



<div class="wp-block-kevinbatdorf-code-block-pro" data-code-block-pro-font-family="" style="font-size:clamp(14px, .875rem, 21px);line-height:clamp(20px, 1.25rem, 30px);--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff"><svg xmlns="http://www.w3.org/2000/svg" width="54" height="14" viewBox="0 0 54 14"><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><circle cx="6" cy="6" r="6" fill="#FF5F56" stroke="#E0443E" stroke-width=".5"></circle><circle cx="26" cy="6" r="6" fill="#FFBD2E" stroke="#DEA123" stroke-width=".5"></circle><circle cx="46" cy="6" r="6" fill="#27C93F" stroke="#1AAB29" stroke-width=".5"></circle></g></svg></span><span role="button" tabindex="0" style="color:#d8dee9ff;display:none" aria-label="复制" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>deb http://repo.mysql.com/apt/ubuntu/ bionic mysql-apt-config
deb http://repo.mysql.com/apt/ubuntu/ bionic mysql-5.7
deb http://repo.mysql.com/apt/ubuntu/ bionic mysql-tools
deb-src http://repo.mysql.com/apt/ubuntu/ bionic mysql-5.7</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki nord" style="background-color: #2e3440ff" tabindex="0"><code><span class="line"><span style="color: #88C0D0">deb</span><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">http://repo.mysql.com/apt/ubuntu/</span><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">bionic</span><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">mysql-apt-config</span></span>
<span class="line"><span style="color: #88C0D0">deb</span><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">http://repo.mysql.com/apt/ubuntu/</span><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">bionic</span><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">mysql-5.7</span></span>
<span class="line"><span style="color: #88C0D0">deb</span><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">http://repo.mysql.com/apt/ubuntu/</span><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">bionic</span><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">mysql-tools</span></span>
<span class="line"><span style="color: #88C0D0">deb-src</span><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">http://repo.mysql.com/apt/ubuntu/</span><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">bionic</span><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">mysql-5.7</span></span></code></pre></div>



<p></p>



<p class="has-small-font-size">更新</p>



<div class="wp-block-kevinbatdorf-code-block-pro" data-code-block-pro-font-family="" style="font-size:clamp(14px, .875rem, 21px);line-height:clamp(20px, 1.25rem, 30px);--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff"><svg xmlns="http://www.w3.org/2000/svg" width="54" height="14" viewBox="0 0 54 14"><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><circle cx="6" cy="6" r="6" fill="#FF5F56" stroke="#E0443E" stroke-width=".5"></circle><circle cx="26" cy="6" r="6" fill="#FFBD2E" stroke="#DEA123" stroke-width=".5"></circle><circle cx="46" cy="6" r="6" fill="#27C93F" stroke="#1AAB29" stroke-width=".5"></circle></g></svg></span><span role="button" tabindex="0" style="color:#d8dee9ff;display:none" aria-label="复制" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>sudo apt update</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki nord" style="background-color: #2e3440ff" tabindex="0"><code><span class="line"><span style="color: #88C0D0">sudo</span><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">apt</span><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">update</span></span></code></pre></div>



<p></p>



<p class="has-small-font-size">执行过程中可能会出现如下错误</p>



<div class="wp-block-kevinbatdorf-code-block-pro" data-code-block-pro-font-family="" style="font-size:clamp(14px, .875rem, 21px);line-height:clamp(20px, 1.25rem, 30px);--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff"><svg xmlns="http://www.w3.org/2000/svg" width="54" height="14" viewBox="0 0 54 14"><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><circle cx="6" cy="6" r="6" fill="#FF5F56" stroke="#E0443E" stroke-width=".5"></circle><circle cx="26" cy="6" r="6" fill="#FFBD2E" stroke="#DEA123" stroke-width=".5"></circle><circle cx="46" cy="6" r="6" fill="#27C93F" stroke="#1AAB29" stroke-width=".5"></circle></g></svg></span><span role="button" tabindex="0" style="color:#d8dee9ff;display:none" aria-label="复制" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>Err:5 http://repo.mysql.com/apt/ubuntu bionic InRelease
  The following signatures couldn't be verified because the public key is not available: NO_PUBKEY B7B3B788A8D3785C
Reading package lists... Done
W: GPG error: http://repo.mysql.com/apt/ubuntu bionic InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY B7B3B788A8D3785C
E: The repository 'http://repo.mysql.com/apt/ubuntu bionic InRelease' is not signed.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki nord" style="background-color: #2e3440ff" tabindex="0"><code><span class="line"><span style="color: #88C0D0">Err:5</span><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">http://repo.mysql.com/apt/ubuntu</span><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">bionic</span><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">InRelease</span></span>
<span class="line"><span style="color: #D8DEE9FF">  </span><span style="color: #88C0D0">The</span><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">following</span><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">signatures</span><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">couldn</span><span style="color: #ECEFF4">&#39;</span><span style="color: #A3BE8C">t be verified because the public key is not available: NO_PUBKEY B7B3B788A8D3785C</span></span>
<span class="line"><span style="color: #A3BE8C">Reading package lists... Done</span></span>
<span class="line"><span style="color: #A3BE8C">W: GPG error: http://repo.mysql.com/apt/ubuntu bionic InRelease: The following signatures couldn</span><span style="color: #ECEFF4">&#39;</span><span style="color: #A3BE8C">t</span><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">be</span><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">verified</span><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">because</span><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">the</span><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">public</span><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">key</span><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">is</span><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">not</span><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">available:</span><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">NO_PUBKEY</span><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">B7B3B788A8D3785C</span></span>
<span class="line"><span style="color: #88C0D0">E:</span><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">The</span><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">repository</span><span style="color: #D8DEE9FF"> </span><span style="color: #ECEFF4">&#39;</span><span style="color: #A3BE8C">http://repo.mysql.com/apt/ubuntu bionic InRelease</span><span style="color: #ECEFF4">&#39;</span><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">is</span><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">not</span><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">signed.</span></span>
<span class="line"><span style="color: #88C0D0">N:</span><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">Updating</span><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">from</span><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">such</span><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">a</span><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">repository</span><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">can</span><span style="color: #ECEFF4">&#39;</span><span style="color: #A3BE8C">t be done securely, and is therefore disabled by default.</span></span>
<span class="line"><span style="color: #A3BE8C">N: See apt-secure(8) manpage for repository creation and user configuration details</span></span></code></pre></div>



<p></p>



<p class="has-small-font-size">执行如下命令即可，<code>B7B3B788A8D3785C</code> 根据实际情况替换</p>



<div class="wp-block-kevinbatdorf-code-block-pro" data-code-block-pro-font-family="" style="font-size:clamp(14px, .875rem, 21px);line-height:clamp(20px, 1.25rem, 30px);--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff"><svg xmlns="http://www.w3.org/2000/svg" width="54" height="14" viewBox="0 0 54 14"><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><circle cx="6" cy="6" r="6" fill="#FF5F56" stroke="#E0443E" stroke-width=".5"></circle><circle cx="26" cy="6" r="6" fill="#FFBD2E" stroke="#DEA123" stroke-width=".5"></circle><circle cx="46" cy="6" r="6" fill="#27C93F" stroke="#1AAB29" stroke-width=".5"></circle></g></svg></span><span role="button" tabindex="0" style="color:#d8dee9ff;display:none" aria-label="复制" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys B7B3B788A8D3785C</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki nord" style="background-color: #2e3440ff" tabindex="0"><code><span class="line"><span style="color: #88C0D0">sudo</span><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">apt-key</span><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">adv</span><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">--keyserver</span><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">keyserver.ubuntu.com</span><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">--recv-keys</span><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">B7B3B788A8D3785C</span></span></code></pre></div>



<p></p>



<p class="has-small-font-size">接着再重新执行更新</p>



<div class="wp-block-kevinbatdorf-code-block-pro" data-code-block-pro-font-family="" style="font-size:clamp(14px, .875rem, 21px);line-height:clamp(20px, 1.25rem, 30px);--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff"><svg xmlns="http://www.w3.org/2000/svg" width="54" height="14" viewBox="0 0 54 14"><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><circle cx="6" cy="6" r="6" fill="#FF5F56" stroke="#E0443E" stroke-width=".5"></circle><circle cx="26" cy="6" r="6" fill="#FFBD2E" stroke="#DEA123" stroke-width=".5"></circle><circle cx="46" cy="6" r="6" fill="#27C93F" stroke="#1AAB29" stroke-width=".5"></circle></g></svg></span><span role="button" tabindex="0" style="color:#d8dee9ff;display:none" aria-label="复制" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>sudo apt update</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki nord" style="background-color: #2e3440ff" tabindex="0"><code><span class="line"><span style="color: #88C0D0">sudo</span><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">apt</span><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">update</span></span></code></pre></div>



<p></p>



<p class="has-medium-font-size">2 . 安装 MySQL</p>



<p></p>



<p class="has-small-font-size">查看支持的 MySQL 版本，此处我们已经可以看到有 <code>5.7.42-1ubuntu18.04</code>，接近成功了</p>



<div class="wp-block-kevinbatdorf-code-block-pro" data-code-block-pro-font-family="" style="font-size:clamp(14px, .875rem, 21px);line-height:clamp(20px, 1.25rem, 30px);--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff"><svg xmlns="http://www.w3.org/2000/svg" width="54" height="14" viewBox="0 0 54 14"><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><circle cx="6" cy="6" r="6" fill="#FF5F56" stroke="#E0443E" stroke-width=".5"></circle><circle cx="26" cy="6" r="6" fill="#FFBD2E" stroke="#DEA123" stroke-width=".5"></circle><circle cx="46" cy="6" r="6" fill="#27C93F" stroke="#1AAB29" stroke-width=".5"></circle></g></svg></span><span role="button" tabindex="0" style="color:#d8dee9ff;display:none" aria-label="复制" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>mysql-server:
  Installed: (none)
  Candidate: 8.0.36-0ubuntu0.22.04.1
  Version table:
     8.0.36-0ubuntu0.22.04.1 500
        500 http://us.archive.ubuntu.com/ubuntu jammy-updates/main amd64 Packages
        500 http://us.archive.ubuntu.com/ubuntu jammy-security/main amd64 Packages
     8.0.28-0ubuntu4 500
        500 http://us.archive.ubuntu.com/ubuntu jammy/main amd64 Packages
     5.7.42-1ubuntu18.04 500
        500 http://repo.mysql.com/apt/ubuntu bionic/mysql-5.7 amd64 Packages</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki nord" style="background-color: #2e3440ff" tabindex="0"><code><span class="line"><span style="color: #88C0D0">mysql-server:</span></span>
<span class="line"><span style="color: #D8DEE9FF">  </span><span style="color: #88C0D0">Installed:</span><span style="color: #D8DEE9FF"> (none)</span></span>
<span class="line"><span style="color: #D8DEE9FF">  </span><span style="color: #88C0D0">Candidate:</span><span style="color: #D8DEE9FF"> </span><span style="color: #B48EAD">8.0</span><span style="color: #A3BE8C">.36-0ubuntu0.22.04.1</span></span>
<span class="line"><span style="color: #D8DEE9FF">  </span><span style="color: #88C0D0">Version</span><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">table:</span></span>
<span class="line"><span style="color: #D8DEE9FF">     </span><span style="color: #88C0D0">8.0.36-0ubuntu0.22.04.1</span><span style="color: #D8DEE9FF"> </span><span style="color: #B48EAD">500</span></span>
<span class="line"><span style="color: #D8DEE9FF">        </span><span style="color: #88C0D0">500</span><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">http://us.archive.ubuntu.com/ubuntu</span><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">jammy-updates/main</span><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">amd64</span><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">Packages</span></span>
<span class="line"><span style="color: #D8DEE9FF">        </span><span style="color: #88C0D0">500</span><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">http://us.archive.ubuntu.com/ubuntu</span><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">jammy-security/main</span><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">amd64</span><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">Packages</span></span>
<span class="line"><span style="color: #D8DEE9FF">     </span><span style="color: #88C0D0">8.0.28-0ubuntu4</span><span style="color: #D8DEE9FF"> </span><span style="color: #B48EAD">500</span></span>
<span class="line"><span style="color: #D8DEE9FF">        </span><span style="color: #88C0D0">500</span><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">http://us.archive.ubuntu.com/ubuntu</span><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">jammy/main</span><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">amd64</span><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">Packages</span></span>
<span class="line"><span style="color: #D8DEE9FF">     </span><span style="color: #88C0D0">5.7.42-1ubuntu18.04</span><span style="color: #D8DEE9FF"> </span><span style="color: #B48EAD">500</span></span>
<span class="line"><span style="color: #D8DEE9FF">        </span><span style="color: #88C0D0">500</span><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">http://repo.mysql.com/apt/ubuntu</span><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">bionic/mysql-5.7</span><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">amd64</span><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">Packages</span></span></code></pre></div>



<p></p>



<p class="has-small-font-size">安装 MySQL 5.7 版本客户端和服务端，版本信息根据上面的输出自行修改</p>



<div class="wp-block-kevinbatdorf-code-block-pro" data-code-block-pro-font-family="" style="font-size:clamp(14px, .875rem, 21px);line-height:clamp(20px, 1.25rem, 30px);--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff"><svg xmlns="http://www.w3.org/2000/svg" width="54" height="14" viewBox="0 0 54 14"><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><circle cx="6" cy="6" r="6" fill="#FF5F56" stroke="#E0443E" stroke-width=".5"></circle><circle cx="26" cy="6" r="6" fill="#FFBD2E" stroke="#DEA123" stroke-width=".5"></circle><circle cx="46" cy="6" r="6" fill="#27C93F" stroke="#1AAB29" stroke-width=".5"></circle></g></svg></span><span role="button" tabindex="0" style="color:#d8dee9ff;display:none" aria-label="复制" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>sudo apt install mysql-client=5.7.42-1ubuntu18.04
sudo apt install mysql-server=5.7.42-1ubuntu18.04</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki nord" style="background-color: #2e3440ff" tabindex="0"><code><span class="line"><span style="color: #88C0D0">sudo</span><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">apt</span><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">install</span><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">mysql-client=</span><span style="color: #B48EAD">5.7</span><span style="color: #A3BE8C">.42-1ubuntu18.04</span></span>
<span class="line"><span style="color: #88C0D0">sudo</span><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">apt</span><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">install</span><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">mysql-server=</span><span style="color: #B48EAD">5.7</span><span style="color: #A3BE8C">.42-1ubuntu18.04</span></span></code></pre></div>



<p></p>



<p class="has-medium-font-size">3 . 验证</p>



<div class="wp-block-kevinbatdorf-code-block-pro" data-code-block-pro-font-family="" style="font-size:clamp(14px, .875rem, 21px);line-height:clamp(20px, 1.25rem, 30px);--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff"><svg xmlns="http://www.w3.org/2000/svg" width="54" height="14" viewBox="0 0 54 14"><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><circle cx="6" cy="6" r="6" fill="#FF5F56" stroke="#E0443E" stroke-width=".5"></circle><circle cx="26" cy="6" r="6" fill="#FFBD2E" stroke="#DEA123" stroke-width=".5"></circle><circle cx="46" cy="6" r="6" fill="#27C93F" stroke="#1AAB29" stroke-width=".5"></circle></g></svg></span><span role="button" tabindex="0" style="color:#d8dee9ff;display:none" aria-label="复制" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>mysql --version</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki nord" style="background-color: #2e3440ff" tabindex="0"><code><span class="line"><span style="color: #88C0D0">mysql</span><span style="color: #D8DEE9FF"> </span><span style="color: #A3BE8C">--version</span></span></code></pre></div>



<p></p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Linux IO模式及 select、poll、epoll详解</title>
		<link>https://codeshell.io/archives/529</link>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Mon, 13 Jun 2022 04:37:31 +0000</pubDate>
				<category><![CDATA[系统]]></category>
		<guid isPermaLink="false">https://codeshell.io/?p=529</guid>

					<description><![CDATA[转载 一 概念说明 在进行解释之前，首先要说明几个概念：&#8211; 用户空间和内核空间&#8211; 进程切换&#8211; 进程的阻塞&#8211; 文件...<p class="read-more"><a class="btn btn-default" href="https://codeshell.io/archives/529"> Read More<span class="screen-reader-text">  Read More</span></a></p>]]></description>
										<content:encoded><![CDATA[
<p><a href="https://segmentfault.com/a/1190000003063859" target="_blank" rel="noreferrer noopener">转载</a></p>



<h2 class="wp-block-heading" id="item-1">一 概念说明</h2>



<hr class="wp-block-separator has-alpha-channel-opacity is-style-wide"/>



<p>在进行解释之前，首先要说明几个概念：<br>&#8211; 用户空间和内核空间<br>&#8211; 进程切换<br>&#8211; 进程的阻塞<br>&#8211; 文件描述符<br>&#8211; 缓存 I/O</p>



<h3 class="wp-block-heading" id="item-1-1">用户空间与内核空间</h3>



<p>现在操作系统都是采用虚拟存储器，那么对32位操作系统而言，它的寻址空间（虚拟地址空间）为4G（2的32次方）。操作系统的核心是内核，独立于普通的应用程序，可以访问受保护的内存空间，也有访问底层硬件设备的所有权限。为了保证用户进程不能直接操作内核（kernel），保证内核的安全，操心系统将虚拟空间划分为两部分，一部分为内核空间，一部分为用户空间。针对linux操作系统而言，将最高的1G字节（从虚拟地址0xC0000000到0xFFFFFFFF），供内核使用，称为内核空间，而将较低的3G字节（从虚拟地址0x00000000到0xBFFFFFFF），供各个进程使用，称为用户空间。</p>



<h3 class="wp-block-heading" id="item-1-2">进程切换</h3>



<p>为了控制进程的执行，内核必须有能力挂起正在CPU上运行的进程，并恢复以前挂起的某个进程的执行。这种行为被称为进程切换。因此可以说，任何进程都是在操作系统内核的支持下运行的，是与内核紧密相关的。</p>



<p>从一个进程的运行转到另一个进程上运行，这个过程中经过下面这些变化：<br>1. 保存处理机上下文，包括程序计数器和其他寄存器。<br>2. 更新PCB信息。<br>3. 把进程的PCB移入相应的队列，如就绪、在某事件阻塞等队列。<br>4. 选择另一个进程执行，并更新其PCB。<br>5. 更新内存管理的数据结构。<br>6. 恢复处理机上下文。</p>



<p>注：<strong>总而言之就是很耗资源</strong>，具体的可以参考这篇文章：<a rel="noreferrer noopener" href="http://guojing.me/linux-kernel-architecture/posts/process-switch/" target="_blank">进程切换</a></p>



<h3 class="wp-block-heading" id="item-1-3">进程的阻塞</h3>



<p>正在执行的进程，由于期待的某些事件未发生，如请求系统资源失败、等待某种操作的完成、新数据尚未到达或无新工作做等，则由系统自动执行阻塞原语(Block)，使自己由运行状态变为阻塞状态。可见，进程的阻塞是进程自身的一种主动行为，也因此只有处于运行态的进程（获得CPU），才可能将其转为阻塞状态。<code>当进程进入阻塞状态，是不占用CPU资源的</code>。</p>



<h3 class="wp-block-heading" id="item-1-4">文件描述符fd</h3>



<p>文件描述符（File descriptor）是计算机科学中的一个术语，是一个用于表述指向文件的引用的抽象化概念。</p>



<p>文件描述符在形式上是一个非负整数。实际上，它是一个索引值，指向内核为每一个进程所维护的该进程打开文件的记录表。当程序打开一个现有文件或者创建一个新文件时，内核向进程返回一个文件描述符。在程序设计中，一些涉及底层的程序编写往往会围绕着文件描述符展开。但是文件描述符这一概念往往只适用于UNIX、Linux这样的操作系统。</p>



<h3 class="wp-block-heading" id="item-1-5">缓存 I/O</h3>



<p>缓存 I/O 又被称作标准 I/O，大多数文件系统的默认 I/O 操作都是缓存 I/O。在 Linux 的缓存 I/O 机制中，操作系统会将 I/O 的数据缓存在文件系统的页缓存（ page cache ）中，也就是说，数据会先被拷贝到操作系统内核的缓冲区中，然后才会从操作系统内核的缓冲区拷贝到应用程序的地址空间。</p>



<p><strong>缓存 I/O 的缺点：</strong><br>数据在传输过程中需要在应用程序地址空间和内核进行多次数据拷贝操作，这些数据拷贝操作所带来的 CPU 以及内存开销是非常大的。</p>



<h2 class="wp-block-heading" id="item-2">二 IO模式</h2>



<hr class="wp-block-separator has-alpha-channel-opacity is-style-wide"/>



<p>刚才说了，对于一次IO访问（以read举例），数据会先被拷贝到操作系统内核的缓冲区中，然后才会从操作系统内核的缓冲区拷贝到应用程序的地址空间。所以说，当一个read操作发生时，它会经历两个阶段：<br>1. 等待数据准备 (Waiting for the data to be ready)<br>2. 将数据从内核拷贝到进程中 (Copying the data from the kernel to the process)</p>



<p>正式因为这两个阶段，linux系统产生了下面五种网络模式的方案。<br>&#8211; 阻塞 I/O（blocking IO）<br>&#8211; 非阻塞 I/O（nonblocking IO）<br>&#8211; I/O 多路复用（ IO multiplexing）<br>&#8211; 信号驱动 I/O（ signal driven IO）<br>&#8211; 异步 I/O（asynchronous IO）</p>



<p>注：由于signal driven IO在实际中并不常用，所以我这只提及剩下的四种IO Model。</p>



<h3 class="wp-block-heading" id="item-2-6">阻塞 I/O（blocking IO）</h3>



<p>在linux中，默认情况下所有的socket都是blocking，一个典型的读操作流程大概是这样：<br></p>



<figure class="wp-block-image size-full"><img fetchpriority="high" decoding="async" width="552" height="331" src="https://codeshell.io/wp-content/uploads/2022/06/1.webp" alt="" class="wp-image-530"/></figure>



<p>当用户进程调用了recvfrom这个系统调用，kernel就开始了IO的第一个阶段：准备数据（对于网络IO来说，很多时候数据在一开始还没有到达。比如，还没有收到一个完整的UDP包。这个时候kernel就要等待足够的数据到来）。这个过程需要等待，也就是说数据被拷贝到操作系统内核的缓冲区中是需要一个过程的。而在用户进程这边，整个进程会被阻塞（当然，是进程自己选择的阻塞）。当kernel一直等到数据准备好了，它就会将数据从kernel中拷贝到用户内存，然后kernel返回结果，用户进程才解除block的状态，重新运行起来。</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p>所以，blocking IO的特点就是在IO执行的两个阶段都被block了。</p>
</blockquote>



<h3 class="wp-block-heading" id="item-2-7">非阻塞 I/O（nonblocking IO）</h3>



<p>linux下，可以通过设置socket使其变为non-blocking。当对一个non-blocking socket执行读操作时，流程是这个样子：<br></p>



<figure class="wp-block-image size-full"><img decoding="async" width="603" height="333" src="https://codeshell.io/wp-content/uploads/2022/06/2.webp" alt="" class="wp-image-531"/></figure>



<p>当用户进程发出read操作时，如果kernel中的数据还没有准备好，那么它并不会block用户进程，而是立刻返回一个error。从用户进程角度讲 ，它发起一个read操作后，并不需要等待，而是马上就得到了一个结果。用户进程判断结果是一个error时，它就知道数据还没有准备好，于是它可以再次发送read操作。一旦kernel中的数据准备好了，并且又再次收到了用户进程的system call，那么它马上就将数据拷贝到了用户内存，然后返回。</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p>所以，nonblocking IO的特点是用户进程需要<strong>不断的主动询问</strong>kernel数据好了没有。</p>
</blockquote>



<h3 class="wp-block-heading" id="item-2-8">I/O 多路复用（ IO multiplexing）</h3>



<p>IO multiplexing就是我们说的select，poll，epoll，有些地方也称这种IO方式为event driven IO。select/epoll的好处就在于单个process就可以同时处理多个网络连接的IO。它的基本原理就是select，poll，epoll这个function会不断的轮询所负责的所有socket，当某个socket有数据到达了，就通知用户进程。</p>



<figure class="wp-block-image size-full"><img decoding="async" width="609" height="326" src="https://codeshell.io/wp-content/uploads/2022/06/3.webp" alt="" class="wp-image-532"/></figure>



<p><code>当用户进程调用了select，那么整个进程会被block</code>，而同时，kernel会“监视”所有select负责的socket，当任何一个socket中的数据准备好了，select就会返回。这个时候用户进程再调用read操作，将数据从kernel拷贝到用户进程。</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p>所以，I/O 多路复用的特点是通过一种机制一个进程能同时等待多个文件描述符，而这些文件描述符（套接字描述符）其中的任意一个进入读就绪状态，select()函数就可以返回。</p>
</blockquote>



<p>这个图和blocking IO的图其实并没有太大的不同，事实上，还更差一些。因为这里需要使用两个system call (select 和 recvfrom)，而blocking IO只调用了一个system call (recvfrom)。但是，用select的优势在于它可以同时处理多个connection。</p>



<p>所以，如果处理的连接数不是很高的话，使用select/epoll的web server不一定比使用multi-threading + blocking IO的web server性能更好，可能延迟还更大。select/epoll的优势并不是对于单个连接能处理得更快，而是在于能处理更多的连接。）</p>



<p>在IO multiplexing Model中，实际中，对于每一个socket，一般都设置成为non-blocking，但是，如上图所示，整个用户的process其实是一直被block的。只不过process是被select这个函数block，而不是被socket IO给block。</p>



<h3 class="wp-block-heading" id="item-2-9">异步 I/O（asynchronous IO）</h3>



<p>inux下的asynchronous IO其实用得很少。先看一下它的流程：<br></p>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="572" height="324" src="https://codeshell.io/wp-content/uploads/2022/06/4.webp" alt="" class="wp-image-533"/></figure>



<p>用户进程发起read操作之后，立刻就可以开始去做其它的事。而另一方面，从kernel的角度，当它受到一个asynchronous read之后，首先它会立刻返回，所以不会对用户进程产生任何block。然后，kernel会等待数据准备完成，然后将数据拷贝到用户内存，当这一切都完成之后，kernel会给用户进程发送一个signal，告诉它read操作完成了。</p>



<h3 class="wp-block-heading" id="item-2-10">总结</h3>



<h4 class="wp-block-heading">blocking和non-blocking的区别</h4>



<p>调用blocking IO会一直block住对应的进程直到操作完成，而non-blocking IO在kernel还准备数据的情况下会立刻返回。</p>



<h4 class="wp-block-heading">synchronous IO和asynchronous IO的区别</h4>



<p>在说明synchronous IO和asynchronous IO的区别之前，需要先给出两者的定义。POSIX的定义是这样子的：<br>&#8211; A synchronous I/O operation causes the requesting process to be blocked until that I/O operation completes;<br>&#8211; An asynchronous I/O operation does not cause the requesting process to be blocked;</p>



<p>两者的区别就在于synchronous IO做”IO operation”的时候会将process阻塞。按照这个定义，之前所述的blocking IO，non-blocking IO，IO multiplexing都属于synchronous IO。</p>



<p>有人会说，non-blocking IO并没有被block啊。这里有个非常“狡猾”的地方，定义中所指的”IO operation”是指真实的IO操作，就是例子中的recvfrom这个system call。non-blocking IO在执行recvfrom这个system call的时候，如果kernel的数据没有准备好，这时候不会block进程。但是，当kernel中数据准备好的时候，recvfrom会将数据从kernel拷贝到用户内存中，这个时候进程是被block了，在这段时间内，进程是被block的。</p>



<p>而asynchronous IO则不一样，当进程发起IO 操作之后，就直接返回再也不理睬了，直到kernel发送一个信号，告诉进程说IO完成。在这整个过程中，进程完全没有被block。</p>



<p><strong>各个IO Model的比较如图所示：</strong><br></p>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="614" height="327" src="https://codeshell.io/wp-content/uploads/2022/06/5.webp" alt="" class="wp-image-534"/></figure>



<p>通过上面的图片，可以发现non-blocking IO和asynchronous IO的区别还是很明显的。在non-blocking IO中，虽然进程大部分时间都不会被block，但是它仍然要求进程去主动的check，并且当数据准备完成以后，也需要进程主动的再次调用recvfrom来将数据拷贝到用户内存。而asynchronous IO则完全不同。它就像是用户进程将整个IO操作交给了他人（kernel）完成，然后他人做完后发信号通知。在此期间，用户进程不需要去检查IO操作的状态，也不需要主动的去拷贝数据。</p>



<h2 class="wp-block-heading" id="item-3">三 I/O 多路复用之select、poll、epoll详解</h2>



<hr class="wp-block-separator has-alpha-channel-opacity is-style-wide"/>



<p>select，poll，epoll都是IO多路复用的机制。I/O多路复用就是通过一种机制，一个进程可以监视多个描述符，一旦某个描述符就绪（一般是读就绪或者写就绪），能够通知程序进行相应的读写操作。但select，poll，epoll本质上都是同步I/O，因为他们都需要在读写事件就绪后自己负责进行读写，也就是说这个读写过程是阻塞的，而异步I/O则无需自己负责进行读写，异步I/O的实现会负责把数据从内核拷贝到用户空间。（这里啰嗦下）</p>



<h3 class="wp-block-heading" id="item-3-11">select</h3>



<pre class="EnlighterJSRAW" data-enlighter-language="c" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">int select (int n, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout);
</pre>



<p>select 函数监视的文件描述符分3类，分别是writefds、readfds、和exceptfds。调用后select函数会阻塞，直到有描述副就绪（有数据 可读、可写、或者有except），或者超时（timeout指定等待时间，如果立即返回设为null即可），函数返回。当select函数返回后，可以 通过遍历fdset，来找到就绪的描述符。</p>



<p>select目前几乎在所有的平台上支持，其良好跨平台支持也是它的一个优点。select的一 个缺点在于单个进程能够监视的文件描述符的数量存在最大限制，在Linux上一般为1024，可以通过修改宏定义甚至重新编译内核的方式提升这一限制，但 是这样也会造成效率的降低。</p>



<h3 class="wp-block-heading" id="item-3-12">poll</h3>



<pre class="EnlighterJSRAW" data-enlighter-language="c" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">int poll (struct pollfd *fds, unsigned int nfds, int timeout);
</pre>



<p>不同与select使用三个位图来表示三个fdset的方式，poll使用一个 pollfd的指针实现。</p>



<pre class="EnlighterJSRAW" data-enlighter-language="c" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">struct pollfd {
    int fd; /* file descriptor */
    short events; /* requested events to watch */
    short revents; /* returned events witnessed */
};
</pre>



<p>pollfd结构包含了要监视的event和发生的event，不再使用select“参数-值”传递的方式。同时，pollfd并没有最大数量限制（但是数量过大后性能也是会下降）。 和select函数一样，poll返回后，需要轮询pollfd来获取就绪的描述符。</p>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p>从上面看，select和poll都需要在返回后，<code>通过遍历文件描述符来获取已经就绪的socket</code>。事实上，同时连接的大量客户端在一时刻可能只有很少的处于就绪状态，因此随着监视的描述符数量的增长，其效率也会线性下降。</p>
</blockquote>



<h3 class="wp-block-heading" id="item-3-13">epoll</h3>



<p>epoll是在2.6内核中提出的，是之前的select和poll的增强版本。相对于select和poll来说，epoll更加灵活，没有描述符限制。epoll使用一个文件描述符管理多个描述符，将用户关系的文件描述符的事件存放到内核的一个事件表中，这样在用户空间和内核空间的copy只需一次。</p>



<h4 class="wp-block-heading">一 epoll操作过程</h4>



<p>epoll操作过程需要三个接口，分别如下：</p>



<pre class="EnlighterJSRAW" data-enlighter-language="c" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">int epoll_create(int size)；//创建一个epoll的句柄，size用来告诉内核这个监听的数目一共有多大
int epoll_ctl(int epfd, int op, int fd, struct epoll_event *event)；
int epoll_wait(int epfd, struct epoll_event * events, int maxevents, int timeout);
</pre>



<p><strong>1. int epoll_create(int size);</strong><br>创建一个epoll的句柄，size用来告诉内核这个监听的数目一共有多大，这个参数不同于select()中的第一个参数，给出最大监听的fd+1的值，<code>参数size并不是限制了epoll所能监听的描述符最大个数，只是对内核初始分配内部数据结构的一个建议</code>。<br>当创建好epoll句柄后，它就会占用一个fd值，在linux下如果查看/proc/进程id/fd/，是能够看到这个fd的，所以在使用完epoll后，必须调用close()关闭，否则可能导致fd被耗尽。</p>



<p><strong>2. int epoll_ctl(int epfd, int op, int fd, struct epoll_event *event)；</strong><br>函数是对指定描述符fd执行op操作。<br>&#8211; epfd：是epoll_create()的返回值。<br>&#8211; op：表示op操作，用三个宏来表示：添加EPOLL_CTL_ADD，删除EPOLL_CTL_DEL，修改EPOLL_CTL_MOD。分别添加、删除和修改对fd的监听事件。<br>&#8211; fd：是需要监听的fd（文件描述符）<br>&#8211; epoll_event：是告诉内核需要监听什么事，struct epoll_event结构如下：</p>



<pre class="EnlighterJSRAW" data-enlighter-language="c" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">struct epoll_event {
  __uint32_t events;  /* Epoll events */
  epoll_data_t data;  /* User data variable */
};

//events可以是以下几个宏的集合：
EPOLLIN ：表示对应的文件描述符可以读（包括对端SOCKET正常关闭）；
EPOLLOUT：表示对应的文件描述符可以写；
EPOLLPRI：表示对应的文件描述符有紧急的数据可读（这里应该表示有带外数据到来）；
EPOLLERR：表示对应的文件描述符发生错误；
EPOLLHUP：表示对应的文件描述符被挂断；
EPOLLET： 将EPOLL设为边缘触发(Edge Triggered)模式，这是相对于水平触发(Level Triggered)来说的。
EPOLLONESHOT：只监听一次事件，当监听完这次事件之后，如果还需要继续监听这个socket的话，需要再次把这个socket加入到EPOLL队列里
</pre>



<p><strong>3. int epoll_wait(int epfd, struct epoll_event * events, int maxevents, int timeout);</strong><br>等待epfd上的io事件，最多返回maxevents个事件。<br>参数events用来从内核得到事件的集合，maxevents告之内核这个events有多大，这个maxevents的值不能大于创建epoll_create()时的size，参数timeout是超时时间（毫秒，0会立即返回，-1将不确定，也有说法说是永久阻塞）。该函数返回需要处理的事件数目，如返回0表示已超时。</p>



<h4 class="wp-block-heading">二 工作模式</h4>



<p>　epoll对文件描述符的操作有两种模式：<strong>LT（level trigger）</strong>和<strong>ET（edge trigger）</strong>。LT模式是默认模式，LT模式与ET模式的区别如下：<br>　　<strong>LT模式</strong>：当epoll_wait检测到描述符事件发生并将此事件通知应用程序，<code>应用程序可以不立即处理该事件</code>。下次调用epoll_wait时，会再次响应应用程序并通知此事件。<br>　　<strong>ET模式</strong>：当epoll_wait检测到描述符事件发生并将此事件通知应用程序，<code>应用程序必须立即处理该事件</code>。如果不处理，下次调用epoll_wait时，不会再次响应应用程序并通知此事件。</p>



<h5 class="wp-block-heading">1. LT模式</h5>



<p>LT(level triggered)是缺省的工作方式，并且同时支持block和no-block socket.在这种做法中，内核告诉你一个文件描述符是否就绪了，然后你可以对这个就绪的fd进行IO操作。如果你不作任何操作，内核还是会继续通知你的。</p>



<h5 class="wp-block-heading">2. ET模式</h5>



<p>ET(edge-triggered)是高速工作方式，只支持no-block socket。在这种模式下，当描述符从未就绪变为就绪时，内核通过epoll告诉你。然后它会假设你知道文件描述符已经就绪，并且不会再为那个文件描述符发送更多的就绪通知，直到你做了某些操作导致那个文件描述符不再为就绪状态了(比如，你在发送，接收或者接收请求，或者发送接收的数据少于一定量时导致了一个EWOULDBLOCK 错误）。但是请注意，如果一直不对这个fd作IO操作(从而导致它再次变成未就绪)，内核不会发送更多的通知(only once)</p>



<p>ET模式在很大程度上减少了epoll事件被重复触发的次数，因此效率要比LT模式高。epoll工作在ET模式的时候，必须使用非阻塞套接口，以避免由于一个文件句柄的阻塞读/阻塞写操作把处理多个文件描述符的任务饿死。</p>



<h5 class="wp-block-heading">3. 总结</h5>



<p><strong>假如有这样一个例子：</strong><br>1. 我们已经把一个用来从管道中读取数据的文件句柄(RFD)添加到epoll描述符<br>2. 这个时候从管道的另一端被写入了2KB的数据<br>3. 调用epoll_wait(2)，并且它会返回RFD，说明它已经准备好读取操作<br>4. 然后我们读取了1KB的数据<br>5. 调用epoll_wait(2)&#8230;&#8230;</p>



<p><strong>LT模式：</strong><br>如果是LT模式，那么在第5步调用epoll_wait(2)之后，仍然能受到通知。</p>



<p><strong>ET模式：</strong><br>如果我们在第1步将RFD添加到epoll描述符的时候使用了EPOLLET标志，那么在第5步调用epoll_wait(2)之后将有可能会挂起，因为剩余的数据还存在于文件的输入缓冲区内，而且数据发出端还在等待一个针对已经发出数据的反馈信息。只有在监视的文件句柄上发生了某个事件的时候 ET 工作模式才会汇报事件。因此在第5步的时候，调用者可能会放弃等待仍在存在于文件输入缓冲区内的剩余数据。</p>



<p>当使用epoll的ET模型来工作时，当产生了一个EPOLLIN事件后，<br>读数据的时候需要考虑的是当recv()返回的大小如果等于请求的大小，那么很有可能是缓冲区还有数据未读完，也意味着该次事件还没有处理完，所以还需要再次读取：</p>



<pre class="EnlighterJSRAW" data-enlighter-language="c" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="1" data-enlighter-title="" data-enlighter-group="">while(rs){
  buflen = recv(activeevents[i].data.fd, buf, sizeof(buf), 0);
  if(buflen &lt; 0){
    // 由于是非阻塞的模式,所以当errno为EAGAIN时,表示当前缓冲区已无数据可读
    // 在这里就当作是该次事件已处理处.
    if(errno == EAGAIN){
        break;
    }
    else{
        return;
    }
  }
  else if(buflen == 0){
     // 这里表示对端的socket已正常关闭.
  }

 if(buflen == sizeof(buf){
      rs = 1;   // 需要再次读取
 }
 else{
      rs = 0;
 }
}
</pre>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p><strong>Linux中的EAGAIN含义</strong></p>
</blockquote>



<p>Linux环境下开发经常会碰到很多错误(设置errno)，其中EAGAIN是其中比较常见的一个错误(比如用在非阻塞操作中)。<br>从字面上来看，是提示再试一次。这个错误经常出现在当应用程序进行一些非阻塞(non-blocking)操作(对文件或socket)的时候。</p>



<p>例如，以 O_NONBLOCK的标志打开文件/socket/FIFO，如果你连续做read操作而没有数据可读。此时程序不会阻塞起来等待数据准备就绪返回，read函数会返回一个错误EAGAIN，提示你的应用程序现在没有数据可读请稍后再试。<br>又例如，当一个系统调用(比如fork)因为没有足够的资源(比如虚拟内存)而执行失败，返回EAGAIN提示其再调用一次(也许下次就能成功)。</p>



<h4 class="wp-block-heading">三 代码演示</h4>



<p>下面是一段不完整的代码且格式不对，意在表述上面的过程，去掉了一些模板代码。</p>



<pre class="EnlighterJSRAW" data-enlighter-language="c" data-enlighter-theme="" data-enlighter-highlight="" data-enlighter-linenumbers="" data-enlighter-lineoffset="" data-enlighter-title="" data-enlighter-group="">#define IPADDRESS   "127.0.0.1"
#define PORT        8787
#define MAXSIZE     1024
#define LISTENQ     5
#define FDSIZE      1000
#define EPOLLEVENTS 100

listenfd = socket_bind(IPADDRESS,PORT);

struct epoll_event events[EPOLLEVENTS];

//创建一个描述符
epollfd = epoll_create(FDSIZE);

//添加监听描述符事件
add_event(epollfd,listenfd,EPOLLIN);

//循环等待
for ( ; ; ){
    //该函数返回已经准备好的描述符事件数目
    ret = epoll_wait(epollfd,events,EPOLLEVENTS,-1);
    //处理接收到的连接
    handle_events(epollfd,events,ret,listenfd,buf);
}

//事件处理函数
static void handle_events(int epollfd,struct epoll_event *events,int num,int listenfd,char *buf)
{
     int i;
     int fd;
     //进行遍历;这里只要遍历已经准备好的io事件。num并不是当初epoll_create时的FDSIZE。
     for (i = 0;i &amp;lt; num;i++)
     {
         fd = events[i].data.fd;
        //根据描述符的类型和事件类型进行处理
         if ((fd == listenfd) &amp;amp;&amp;amp;(events[i].events &amp;amp; EPOLLIN))
            handle_accpet(epollfd,listenfd);
         else if (events[i].events &amp;amp; EPOLLIN)
            do_read(epollfd,fd,buf);
         else if (events[i].events &amp;amp; EPOLLOUT)
            do_write(epollfd,fd,buf);
     }
}

//添加事件
static void add_event(int epollfd,int fd,int state){
    struct epoll_event ev;
    ev.events = state;
    ev.data.fd = fd;
    epoll_ctl(epollfd,EPOLL_CTL_ADD,fd,&amp;amp;ev);
}

//处理接收到的连接
static void handle_accpet(int epollfd,int listenfd){
     int clifd;     
     struct sockaddr_in cliaddr;     
     socklen_t  cliaddrlen;     
     clifd = accept(listenfd,(struct sockaddr*)&amp;amp;cliaddr,&amp;amp;cliaddrlen);     
     if (clifd == -1)         
     perror("accpet error:");     
     else {         
         printf("accept a new client: %s:%d\n",inet_ntoa(cliaddr.sin_addr),cliaddr.sin_port);                       //添加一个客户描述符和事件         
         add_event(epollfd,clifd,EPOLLIN);     
     } 
}

//读处理
static void do_read(int epollfd,int fd,char *buf){
    int nread;
    nread = read(fd,buf,MAXSIZE);
    if (nread == -1)     {         
        perror("read error:");         
        close(fd); //记住close fd        
        delete_event(epollfd,fd,EPOLLIN); //删除监听 
    }
    else if (nread == 0)     {         
        fprintf(stderr,"client close.\n");
        close(fd); //记住close fd       
        delete_event(epollfd,fd,EPOLLIN); //删除监听 
    }     
    else {         
        printf("read message is : %s",buf);        
        //修改描述符对应的事件，由读改为写         
        modify_event(epollfd,fd,EPOLLOUT);     
    } 
}

//写处理
static void do_write(int epollfd,int fd,char *buf) {     
    int nwrite;     
    nwrite = write(fd,buf,strlen(buf));     
    if (nwrite == -1){         
        perror("write error:");        
        close(fd);   //记住close fd       
        delete_event(epollfd,fd,EPOLLOUT);  //删除监听    
    }else{
        modify_event(epollfd,fd,EPOLLIN); 
    }    
    memset(buf,0,MAXSIZE); 
}

//删除事件
static void delete_event(int epollfd,int fd,int state) {
    struct epoll_event ev;
    ev.events = state;
    ev.data.fd = fd;
    epoll_ctl(epollfd,EPOLL_CTL_DEL,fd,&amp;amp;ev);
}

//修改事件
static void modify_event(int epollfd,int fd,int state){     
    struct epoll_event ev;
    ev.events = state;
    ev.data.fd = fd;
    epoll_ctl(epollfd,EPOLL_CTL_MOD,fd,&amp;amp;ev);
}

//注：另外一端我就省了
</pre>



<h4 class="wp-block-heading">四 epoll总结</h4>



<p>在 select/poll中，进程只有在调用一定的方法后，内核才对所有监视的文件描述符进行扫描，而<strong>epoll事先通过epoll_ctl()来注册一 个文件描述符，一旦基于某个文件描述符就绪时，内核会采用类似callback的回调机制，迅速激活这个文件描述符，当进程调用epoll_wait() 时便得到通知</strong>。(<code>此处去掉了遍历文件描述符，而是通过监听回调的的机制</code>。这正是epoll的魅力所在。)</p>



<p><strong>epoll的优点主要是一下几个方面：</strong><br>1. 监视的描述符数量不受限制，它所支持的FD上限是最大可以打开文件的数目，这个数字一般远大于2048,举个例子,在1GB内存的机器上大约是10万左 右，具体数目可以cat /proc/sys/fs/file-max察看,一般来说这个数目和系统内存关系很大。select的最大缺点就是进程打开的fd是有数量限制的。这对 于连接数量比较大的服务器来说根本不能满足。虽然也可以选择多进程的解决方案( Apache就是这样实现的)，不过虽然linux上面创建进程的代价比较小，但仍旧是不可忽视的，加上进程间数据同步远比不上线程间同步的高效，所以也不是一种完美的方案。</p>



<ol class="wp-block-list">
<li>IO的效率不会随着监视fd的数量的增长而下降。epoll不同于select和poll轮询的方式，而是通过每个fd定义的回调函数来实现的。只有就绪的fd才会执行回调函数。</li>
</ol>



<blockquote class="wp-block-quote is-layout-flow wp-block-quote-is-layout-flow">
<p>如果没有大量的idle -connection或者dead-connection，epoll的效率并不会比select/poll高很多，但是当遇到大量的idle- connection，就会发现epoll的效率大大高于select/poll。</p>
</blockquote>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>十年学会编程</title>
		<link>https://codeshell.io/archives/479</link>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Mon, 06 Apr 2020 13:43:11 +0000</pubDate>
				<category><![CDATA[闲谈]]></category>
		<guid isPermaLink="false">https://codeshell.io/?p=479</guid>

					<description><![CDATA[转载 这篇文章已经有很多人翻译过了，我之所以再搞一次，首先是我觉得这文章真的很好，值得一搞再搞，其次，几乎所有的版本都漏掉了一些语句，我猜可能是英文版更新过，但...<p class="read-more"><a class="btn btn-default" href="https://codeshell.io/archives/479"> Read More<span class="screen-reader-text">  Read More</span></a></p>]]></description>
										<content:encoded><![CDATA[
<p><a href="https://liuyandong.com/2017/10/25/122/" target="_blank" rel="noreferrer noopener">转载</a></p>



<p>这篇文章已经有很多人翻译过了，我之所以再搞一次，首先是我觉得这文章真的很好，值得一搞再搞，其次，几乎所有的版本都漏掉了一些语句，我猜可能是英文版更新过，但是，中文版没有与时俱进，最后是我没有找到那种<strong>一段英文，一段翻译</strong>的版本。如果再有人在我的公众号里问我如何学习编程的话，我就可以把这个发给他了。</p>



<h1 class="wp-block-heading">Teach Yourself Programming in Ten Years</h1>



<h3 class="wp-block-heading">Peter NorviG</h3>



<h2 class="wp-block-heading">Why is everyone in such a rush？</h2>



<h2 class="wp-block-heading">为何每个人都急于求成?</h2>



<p>Walk into any bookstore, and you’ll see how to&nbsp;<em>Teach Yourself Java in 24 Hours</em>&nbsp;alongside endless variations offering to teach C, SQL, Ruby, Algorithms, and so on in a few days or hours. The Amazon advanced search for [title: teach, yourself, hours, since: 2000&nbsp;and found 512 such books. Of the top ten, nine are programming books (the other is about bookkeeping). Similar results come from replacing “teach yourself” with “learn” or “hours” with “days.”</p>



<p>随便走进一家书店，都会看到类似《24小时学会Java》这样的书，旁边摆着的是大量诸如在几天，几小时之内学会C语言，SQL，Ruby以及算法这样的书。如果使用Amazon上的高级搜索，使用title: teach, yourself, hours, since: 2000这个关键字来搜索，将会返回512本书。最靠前的10本书中，有9本是编程的书（唯一的例外是一本记账的书）。如果把关键字”teach yourself”替换成”learn”，或者将”hours”替换成”days”，返回的结果大同小异。</p>



<p>The conclusion is that either people are in a big rush to learn about programming, or that programming is somehow fabulously easier to learn than anything else. Felleisen&nbsp;<em>et al.</em>&nbsp;give a nod to this trend in their book&nbsp;<em>How to Design Programs</em>, when they say “Bad programming is easy.&nbsp;<em>Idiots</em>&nbsp;can learn it in&nbsp;<em>21 days</em>, even if they are&nbsp;<em>dummies</em>.” The Abtruse Goose comic also had&nbsp;their take.</p>



<p>很明显，人们在学习编程的时候喜欢大跃进，或者认为编程比起其它事情来，是小菜一碟的事。Felleisen在他的书《How to Design Program》里说：“编烂程一点也不难。傻瓜也可以在21天内学会，即使他们是傻逼。”在搞笑漫画网站Abtruse Goose也在这个漫画中表达了同样的看法。</p>



<p>Let’s analyze what a title like&nbsp;<em>Teach Yourself C++ in 24 Hours</em>&nbsp;could mean:</p>



<p>我们来看看类似《24小时自学C++》这种标题党，到底说的什么鬼东西：</p>



<ul class="wp-block-list"><li><strong>Teach Yourself</strong>: In 24 hours you won’t have time to write several significant programs, and learn from your successes and failures with them. You won’t have time to work with an experienced programmer and understand what it is like to live in a C++ environment. In short, you won’t have time to learn much. So the book can only be talking about a superficial familiarity, not a deep understanding. As Alexander Pope said, a little learning is a dangerous thing.</li><li><strong>自学:</strong>&nbsp;24小时之内，你没有时间写几个有意义的程序，也就无法从成功或失败中学到经验。24小时之内，你没有时间和一个有经验的程序员合作交流，也就无从理解使用C++编程的真实场景。简单来说，时间太短，你啥也学不到。因此，有这种干货标题的速成书，只是让你走马观花的瞧一下，绝非深入的理解。18世纪的英国诗人亚历山大·蒲柏[……1]曾说过：“一知半解”是一件危险的事情。[……1]：这个哥哥还给牛顿写了最出名的墓志铭之一：“<strong>自然和自然律隐没在黑暗中；上帝说，让牛顿去吧！遂一片光明。</strong>”</li><li><strong>C++:</strong>&nbsp;In 24 hours you might be able to learn some of the syntax of C++ (if you already know another language), but you couldn’t learn much about how to use the language. In short, if you were, say, a Basic programmer, you could learn to write programs in the style of Basic using C++ syntax, but you couldn’t learn what C++ is actually good (and bad) for. So what’s the point?&nbsp;&nbsp;Alan Perlis&nbsp;once said: “A language that doesn’t affect the way you think about programming, is not worth knowing”. One possible point is that you have to learn a tiny bit of C++ (or more likely, something like JavaScript or Processing) because you need to interface with an existing tool to accomplish a specific task. But then you’re not learning how to program; you’re learning to accomplish that task.</li><li><strong>C++:</strong>&nbsp;(如果你有一定的编程基础)，在24小时之内，能学会一些C++的语法，但是，仅此而已了。如果你以前是个Basic语言的程序员，你可以写一些语法是C++，但是风格是Basic的程序，但是，24小时之内，C++语言的精华或糟粕，你都学不到。重点是什么？(首界图灵奖得主)Alan Perlis曾说过：“不能影响你编程思维方式的语言，是不值得学习的。”一个更加可能的场景是，在工作中，你不得不学习C++（或者JavaScript，Processing之类）的一小部分，来调用一些原有的接口，完成某个特定的任务。这种情况下，表面上说是在学习如何编程，其实只是在应付一下手上的活。</li><li><strong>in 24 Hours:</strong>&nbsp;Unfortunately, this is not enough, as the next section shows.</li><li><strong>24小时内:</strong>很不幸，24小时太少了，原因下面告诉你。</li></ul>



<h2 class="wp-block-heading">Teach Yourself Programming in Ten Years</h2>



<h2 class="wp-block-heading">十年学会编程</h2>



<p>Researchers (Bloom (1985),&nbsp;Bryan &amp; Harter (1899),&nbsp;Hayes (1989),&nbsp;Simmon &amp; Chase (1973)) have shown it takes about ten years to develop expertise in any of a wide variety of areas, including chess playing, music composition, telegraph operation, painting, piano playing, swimming, tennis, and research in neuropsychology and topology. The key is&nbsp;<em>deliberative</em>&nbsp;practice: not just doing it again and again, but challenging yourself with a task that is just beyond your current ability, trying it, analyzing your performance while and after doing it, and correcting any mistakes. Then repeat. And repeat again. There appear to be no real shortcuts: even Mozart, who was a musical prodigy at age 4, took 13 more years before he began to produce world-class music. In another genre, the Beatles seemed to burst onto the scene with a string of #1 hits and an appearance on the Ed Sullivan show in 1964. But they had been playing small clubs in Liverpool and Hamburg since 1957, and while they had mass appeal early on, their first great critical success,&nbsp;<em>Sgt. Peppers</em>, was released in 1967.&nbsp;</p>



<p>研究表明，想在任何领域成为专家，大概需要10年的时间，这些领域包括下棋，作曲，发电报，弹钢琴，游泳，打网球，研究神经心理学和拓扑学。关键在于有针对性的训练，而不是漫无目的重复，训练的内容要刚好超过你现有的水平，练习以后要分析你的表现，改正发现的错误，然后重复，再重复。没有什么捷径可走，即使是Mozart，一个4岁就能弹琴的音乐天才，也是用了13年的时间，才真正的写出世界级的音乐作品。在流行音乐上，Beatles好像是在1964年访美期间一夜成名的。实际上，他们从1957年就已经开始在利物浦和汉堡的小酒馆里唱歌了，他们组建乐队的时间就更早了，他们第一张取得巨大成功的专辑《佩帕军士》，是在1967年发行的。</p>



<p>Malcolm Gladwell&nbsp;has popularized the idea, although he concentrates on 10,000 hours, not 10 years. Henri Cartier-Bresson (1908-2004) had another metric: “Your first 10,000 photographs are your worst.” (He didn’t anticipate that with digital cameras, some people can reach that mark in a week.) True expertise may take a lifetime: Samuel Johnson (1709-1784) said “Excellence in any department can be attained only by the labor of a lifetime; it is not to be purchased at a lesser price.” And Chaucer (1340-1400) complained “the lyf so short, the craft so long to lerne.” Hippocrates (c. 400BC) is known for the excerpt “ars longa, vita brevis”, which is part of the longer quotation “Ars longa, vita brevis, occasio praeceps, experimentum periculosum, iudicium difficile”, which in English renders as “Life is short, [the] craft long, opportunity fleeting, experiment treacherous, judgment difficult.” Of course, no single number can be the final answer: it doesn’t seem reasonable to assume that all skills (e.g., programming, chess playing, checkers playing, and music playing) could all require exactly the same amount of time to master, nor that all people will take exactly the same amount of time. As Prof.&nbsp;K. Anders Ericsson&nbsp;puts it, “In most domains it’s remarkable how much time even the most talented individuals need in order to reach the highest levels of performance. The 10,000 hour number just gives you a sense that we’re talking years of 10 to 20 hours a week which those who some people would argue are the most innately talented individuals still need to get to the highest level.”</p>



<p>马尔科姆·格拉德威尔让这个理论广为人知，虽然他说的是另一个说法，10，000个小时而不是10年(这本书有中文翻译版异类 : 不一样的成功启示录)。法国现实主义摄影大师亨利·卡蒂埃-布列松有另外一个标准，他说你的前10,000张照片是你最差的。(当然，这个摄影大师没有意识到数码相机的出现，很多人能在一周内就可以拍10,000张照片)真正的大师要用一生来完成，英国作家，文学评论家和诗人塞缪尔·约翰逊说过：“在任何领域取得卓越的成就都要用一生的努力，不要妄想可以投机取巧。”英国的诗人乔叟也曾经说过：”吾生也有涯 而知也无涯。”同样，公元前400年的希波克拉底也表达过类似的意思，他也认为艺术没有止境，生命却有尽头。他说的这句话有个更长的版本，翻译成英语的意思是：“生命有尽头，艺术无止境，机遇转瞬即逝，练功走火入魔，决定优柔寡断。”当然，不会有一个确定的答案告诉你需要多长时间，毕竟，假设掌握所有的技能(比如编程，下棋，跳棋和音乐)需要相同的时间也不合适，不同的人也会用不同的时间。K.Anders Ericsson教授说过：“值得注意的是，在大多数领域，即使你是个天才，要达到专家级别的高水平仍然需要时间。10，000个小时只是给你一个概念，一个天才，如果每周练习10到20个小时的时间，仍然需要数年时间才能达到专家级别的水平。”</p>



<p><strong>So You Want to be a Programmer</strong></p>



<p><strong>所以你想成为一个程序员</strong></p>



<p>Here’s my recipe for programming success:</p>



<p>这是我编程成功的秘笈:</p>



<p>Get&nbsp;<strong>interested</strong>&nbsp;in programming, and do some because it is fun. Make sure that it keeps being enough fun so that you will be willing to put in your ten years/10,000 hours.</p>



<p>要对编程感兴趣，要从中能获得快乐。保证编程足够有趣，这样才能让你花10年的时间或者10，000个小时在上面也不觉得枯燥无味。</p>



<p><strong>Program</strong>. The best kind of learning is&nbsp;learning by doing. To put it more technically, “the maximal level of performance for individuals in a given domain is not attained automatically as a function of extended experience, but the level of performance can be increased even by highly experienced individuals as a result of deliberate efforts to improve.”&nbsp;(p. 366)&nbsp;and “the most effective learning requires a well-defined task with an appropriate difficulty level for the particular individual, informative feedback, and opportunities for repetition and corrections of errors.” (p. 20-21) The book&nbsp;<em>Cognition in Practice: Mind, Mathematics, and Culture in Everyday Life</em>&nbsp;is an interesting reference for this viewpoint.</p>



<p>动手编程。最好的学习方法是边学边做。常言道：“人的最高功力并不能通过做一天和尚撞一天钟这样的重复经验获得，但是，最高的功力可以通过有针对性的日复一日年复一年的训练来获得。”并且，“最有效果的学习需要有针对性的任务，这些任务的难度还要因人而异，并且有合理的反馈渠道，并能够根据这些反馈作出相应的改进。”这些观点引用自《Cognition in Practice: Mind, Mathematics, and Culture in Everyday Life》这本书里。</p>



<p><strong>Talk with</strong>&nbsp;other programmers; read other programs. This is more important than any book or training course.</p>



<p>和其他的程序员交流；阅读别人的代码。这比看书或者参加培训课程要重要。</p>



<p>If you want, put in four years at a&nbsp;<strong>college</strong>&nbsp;(or more at a graduate school). This will give you access to some jobs that require credentials, and it will give you a deeper understanding of the field, but if you don’t enjoy school, you can (with some dedication) get similar experience on your own or on the job. In any case, book learning alone won’t be enough. “Computer science education cannot make anybody an expert programmer any more than studying brushes and pigment can make somebody an expert painter” says Eric Raymond, author of&nbsp;<em>The New Hacker’s Dictionary</em>. One of the best programmers I ever hired had only a High School degree; he’s produced a lot of&nbsp;greatsoftware, has his own&nbsp;news group, and made enough in stock options to buy his own&nbsp;nightclub.</p>



<p>如果你愿意，在大学里花上四年时间（或者再读个研）。这能让你获得一些工作机会，也能让你在这个领域有更深入的了解。但是，如果你一上学就头痛，直接去工作也能获得相同的经验。无论是什么情况，读死书肯定是不行的。计算机科学不会让你成为编程专家，就像学习画笔和颜料不可能让你成为画家一样。这是Eric　Raymond说的，他是New Hacker’s Dictionary字典的作者。我雇佣过的最好的程序员是个高中毕业的学生，他创造了伟大的软件，Mozilla，他拥有自己的新闻组，赚到了足够多的钱买了自己的酒吧。</p>



<p>Work on&nbsp;<strong>projects with</strong>&nbsp;other programmers. Be the best programmer on some projects; be the worst on some others. When you’re the best, you get to test your abilities to lead a project, and to inspire others with your vision. When you’re the worst, you learn what the masters do, and you learn what they don’t like to do (because they make you do it for them).</p>



<p>和其他的程序员一起参与一些项目。在一些项目中成为最出色的程序员；在另一些项目中当最差劲的程序员。在当最出色的程序员的时候，要测试你领导项目的能力，用你的视野来启发别人。如果你是项目中最差的那个，要学习牛人们在做什么，如果他们不喜欢做的，你要拿来做。</p>



<p>Work on&nbsp;<strong>projects after</strong>&nbsp;other programmers. Understand a program written by someone else. See what it takes to understand and fix it when the original programmers are not around. Think about how to design your programs to make it easier for those who will maintain them after you.</p>



<p>接手并推进别人的项目。理解其他人写的代码。如果别人有没有考虑到的问题，你能理解并修复这些问题。思考并设计你的软件，让这些软件容易被他人维护。</p>



<p>Learn at least a half dozen&nbsp;<strong>programming languages</strong>. Include one language that emphasizes class abstractions (like Java or C++), one that emphasizes functional abstraction (like Lisp or ML or Haskell), one that supports syntactic abstraction (like Lisp), one that supports declarative specifications (like Prolog or C++ templates), and one that emphasizes parallelism (like Clojure or Go).&nbsp;</p>



<p>学习至少6种(我不太清楚英语中的half dozen是什么意思，是虚指还是就是6种)编程语言。这6种语言中，包括一种支持抽象类的(例如Java或者C++)，一种支持函数的(Lisp, ML或者Haskell)，一种支持语义抽象的(Lisp)，一种支持声明规范的(Prolog或者C++模板)，还有一种支持并发的(Clojure或Go)。</p>



<p>Remember that there is a “<strong>computer</strong>“ in “computer science”. Know how long it takes your computer to execute an instruction, fetch a word from memory (with and without a cache miss), read consecutive words from disk, and seek to a new location on disk. (Answers here.)&nbsp;</p>



<p>记住，在“计算机科学”中在“计算机”这个词语。理解执行一条指令要花多长时间，从内存中取一个字（要考虑缓存有没有命中的情况）要多久，从硬盘中连续读字节要多久，在硬盘中寻址定位要多久？</p>



<p>Get involved in a language&nbsp;<strong>standardization</strong>&nbsp;effort. It could be the ANSI C++ committee, or it could be deciding if your local coding style will have 2 or 4 space indentation levels. Either way, you learn about what other people like in a language, how deeply they feel so, and perhaps even a little about why they feel so.</p>



<p>参加语言的标准化工作。这可能是有关 ANSI C++ 委员会，也可能是缩进的风格是两格缩进或四格缩进。无论如何，你能从中学到其他人对语言的喜好，也能了解到他们热爱的程度，甚至也许能知道一点他们为什么他们会这样认为？</p>



<p>Have the good sense to&nbsp;<strong>get off</strong>&nbsp;the language standardization effort as quickly as possible.</p>



<p>知道何时能从标准化语言的工作中脱身，越快越好。</p>



<p>With all that in mind, its questionable how far you can get just by book learning. Before my first child was born, I read all the&nbsp;<em>How To</em>&nbsp;books, and still felt like a clueless novice. 30 Months later, when my second child was due, did I go back to the books for a refresher? No. Instead, I relied on my personal experience, which turned out to be far more useful and reassuring to me than the thousands of pages written by experts.</p>



<p>很难说能从书本中学到多少东西。我第一个小孩出生的时候，我读了所有的“如何做”系列的书，但是，没有什么头绪。30个月以后，当我的第二个孩子出生，我还要重温一下那些书么？当然不用了！我都已经是老司机了，我完全靠我自己的经验，事实也证明我自己的经验要胜过那些专家们写的上千页的书。</p>



<p>Fred Brooks, in his essay&nbsp;<em>No Silver Bullet</em>&nbsp;identified a three-part plan for finding great software designers:</p>



<p>弗雷德·布鲁克斯在他的书《没有银弹》中给出了三条建议：</p>



<ol class="wp-block-list"><li>Systematically identify top designers as early as possible.尽早地系统地识别出顶级设计师</li><li>Assign a career mentor to be responsible for the development of the prospect and carefully keep a career file.每个人给分配一个职业规划的导师</li><li>Provide opportunities for growing designers to interact and stimulate each other.让成长中的设计师有机会互相切磋武艺</li></ol>



<p>This assumes that some people already have the qualities necessary for being a great designer; the job is to properly coax them along.&nbsp;&nbsp;Alan Perlis&nbsp;put it more succinctly: “Everyone can be taught to sculpt: Michelangelo would have had to be taught how not to. So it is with the great programmers”. Perlis is saying that the greats have some internal quality that transcends their training. But where does the quality come from? Is it innate? Or do they develop it through diligence? As Auguste Gusteau (the fictional chef in&nbsp;<em>Ratatouille</em>) puts it, “anyone can cook, but only the fearless can be great.” I think of it more as willingness to devote a large portion of one’s life to deliberative practice. But maybe&nbsp;<em>fearless</em>&nbsp;is a way to summarize that. Or, as Gusteau’s critic, Anton Ego, says: “Not everyone can become a great artist, but a great artist can come from anywhere.”</p>



<p>此处假设有一些人天生有成为伟大设计师的潜质，然后，就是正确的去引导他们。艾伦·佩里斯一针见血地说：”假如每个人都可以学会雕刻，那就得教米开朗基罗哪些事不要去做。对于伟大程序员，也是如此。”Perlis认为，伟大的人有一种内在的特质，这种特质往往比接受训练更重要。但是，这些特质是从哪里来的呢？与生俱来的？还是通过后天勤奋而来的？正如 动画片《料理鼠王》里的幻象大厨Auguste Gusteau说的那样：“谁都能做饭，但只有那些无所畏惧的人才能成为大厨！”我认为“把你生命中的大部分时间花在有针对性的练习上”这种精神，看作一种自愿奉献的精神！但或许“无所畏惧”才是体现这种精神的真谛。或者，就像是《料理鼠王》里那个与 Gusteau 作对的刻薄的美食评论家 Anton Ego 说的那样：“不是任何人都能成为伟大的艺术家，不过，伟大的艺术家可以来自任何地方。”</p>



<p>So go ahead and buy that Java/Ruby/Javascript/PHP book; you’ll probably get some use out of it. But you won’t change your life, or your real overall expertise as a programmer in 24 hours or 21 days. How about working hard to continually improve over 24 months? Well, now you’re starting to get somewhere…</p>



<p>所以，尽管买本 Java/Ruby/Javascript/PHP 的书吧。你可能会从中学到点儿有用的东西。但作为一个程序员，在 21 天内或 24 小时内改变你的人生，或者提高你实际的编程水平，这是不可能的。你尝试过连续 24 个月不间断的努力提高自己么？好吧，好吧，你该上路了……</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>C里面数组和引用</title>
		<link>https://codeshell.io/archives/427</link>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Tue, 10 Mar 2020 03:39:01 +0000</pubDate>
				<category><![CDATA[c语言]]></category>
		<guid isPermaLink="false">https://codeshell.io/?p=427</guid>

					<description><![CDATA[]]></description>
										<content:encoded><![CDATA[
<div class="wp-block-kevinbatdorf-code-block-pro" data-code-block-pro-font-family="" style="font-size:clamp(14px, .875rem, 21px);line-height:clamp(20px, 1.25rem, 30px);--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff"><svg xmlns="http://www.w3.org/2000/svg" width="54" height="14" viewBox="0 0 54 14"><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><circle cx="6" cy="6" r="6" fill="#FF5F56" stroke="#E0443E" stroke-width=".5"></circle><circle cx="26" cy="6" r="6" fill="#FFBD2E" stroke="#DEA123" stroke-width=".5"></circle><circle cx="46" cy="6" r="6" fill="#27C93F" stroke="#1AAB29" stroke-width=".5"></circle></g></svg></span><span role="button" tabindex="0" style="color:#d8dee9ff;display:none" aria-label="复制" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>int a&#91;5&#93;;
// 取a相当于(a+0)，也就是符号表中找到a，然后取数组地址加上0偏移地址，也就是数组第一个元素地址，返回类型是一个指向元素类型的指针
print("%p\n", a);
// 引用a，是直接在符号表中找到a，然后直接返回符号表中记录的数组地址，返回的类型是一个指向数组的指针
print("%p\n", &amp;a);</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki nord" style="background-color: #2e3440ff" tabindex="0"><code><span class="line"><span style="color: #81A1C1">int</span><span style="color: #D8DEE9FF"> a</span><span style="color: #ECEFF4">&#91;</span><span style="color: #B48EAD">5</span><span style="color: #ECEFF4">&#93;</span><span style="color: #81A1C1">;</span></span>
<span class="line"><span style="color: #616E88">// 取a相当于(a+0)，也就是符号表中找到a，然后取数组地址加上0偏移地址，也就是数组第一个元素地址，返回类型是一个指向元素类型的指针</span></span>
<span class="line"><span style="color: #88C0D0">print</span><span style="color: #ECEFF4">(</span><span style="color: #ECEFF4">&quot;</span><span style="color: #A3BE8C">%p</span><span style="color: #EBCB8B">\n</span><span style="color: #ECEFF4">&quot;</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> a</span><span style="color: #ECEFF4">)</span><span style="color: #81A1C1">;</span></span>
<span class="line"><span style="color: #616E88">// 引用a，是直接在符号表中找到a，然后直接返回符号表中记录的数组地址，返回的类型是一个指向数组的指针</span></span>
<span class="line"><span style="color: #88C0D0">print</span><span style="color: #ECEFF4">(</span><span style="color: #ECEFF4">&quot;</span><span style="color: #A3BE8C">%p</span><span style="color: #EBCB8B">\n</span><span style="color: #ECEFF4">&quot;</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">&amp;</span><span style="color: #D8DEE9">a</span><span style="color: #ECEFF4">)</span><span style="color: #81A1C1">;</span></span></code></pre></div>



<p></p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>计算机数据存储的一些总结</title>
		<link>https://codeshell.io/archives/425</link>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Tue, 10 Mar 2020 03:32:07 +0000</pubDate>
				<category><![CDATA[系统]]></category>
		<guid isPermaLink="false">https://codeshell.io/?p=425</guid>

					<description><![CDATA[补码的本质 补码的本质是利用溢出来使加法与减法有相同结果。假设用8位来表示一个有符号数，那么溢出值为28 = 256。假如我们要计算x-127的值，那么，有： ...<p class="read-more"><a class="btn btn-default" href="https://codeshell.io/archives/425"> Read More<span class="screen-reader-text">  Read More</span></a></p>]]></description>
										<content:encoded><![CDATA[
<ol class="wp-block-list"><li>补码的本质<ul><li>补码的本质是利用溢出来使加法与减法有相同结果。假设用8位来表示一个有符号数，那么溢出值为2<sup><i>8</i></sup> = 256。假如我们要计算x-127的值，那么，有：<ul><li>128 &#8211;  256 = -127</li><li>x + 128 &#8211; 256 = x + (-127)</li></ul></li><li>由于我们限定了8位表示一个数，所以计算机计算时会丢弃溢出位，也就是计算机帮我们做了上面的减256这一步，所以x + 128 = x &#8211; 127。同时，可以知道，-127的补码是128。</li></ul></li><li>为什么用补码<ul><li>方便CPU用加法器算减法</li></ul></li><li>运行时溢出（非加减法溢出）后的具体行为是什么决定<ul><li>具体行为由编译器决定，CPU只负责计算，unsigned整型溢出C语言规定把溢出位丢弃，signed整型溢出则看编译器行为。</li></ul></li></ol>



<p></p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>进程、线程、协程</title>
		<link>https://codeshell.io/archives/404</link>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Tue, 08 Jan 2019 10:45:20 +0000</pubDate>
				<category><![CDATA[系统]]></category>
		<category><![CDATA[协程]]></category>
		<category><![CDATA[线程]]></category>
		<category><![CDATA[进程]]></category>
		<guid isPermaLink="false">https://blog.lcodelite.com/?p=404</guid>

					<description><![CDATA[参考：http://easyswoole.com/Manual/3.x/Cn/_book/noobCourse/Coroutine.html协程不是进程或线程，...<p class="read-more"><a class="btn btn-default" href="https://codeshell.io/archives/404"> Read More<span class="screen-reader-text">  Read More</span></a></p>]]></description>
										<content:encoded><![CDATA[
<p>参考：<a href="http://easyswoole.com/Manual/3.x/Cn/_book/noobCourse/Coroutine.html" target="_blank" rel="noreferrer noopener" aria-label="（在新窗口打开）">http://easyswoole.com/Manual/3.x/Cn/_book/noobCourse/Coroutine.html</a><br>协程不是进程或线程，其执行过程更类似于子例程，或者说不带返回值的函数调用。<br>一个程序可以包含多个协程，可以对比与一个进程包含多个线程，因而下面我们来比较协程和线程。我们知道多个线程相对独立，有自己的上下文，切换受系统控制；而协程也相对独立，有自己的上下文，但是其切换由自己控制，由当前协程切换到其他协程由当前协程来控制。</p>



<figure class="wp-block-image"><img loading="lazy" decoding="async" width="620" height="1024" src="https://blog.lcodelite.com/wp-content/uploads/2019/01/Coroutine-620x1024.png" alt="" class="wp-image-405" srcset="https://codeshell.io/wp-content/uploads/2019/01/Coroutine-620x1024.png 620w, https://codeshell.io/wp-content/uploads/2019/01/Coroutine-182x300.png 182w, https://codeshell.io/wp-content/uploads/2019/01/Coroutine.png 725w" sizes="auto, (max-width: 620px) 100vw, 620px" /></figure>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>TCP/IP模型与OSI模型的对比</title>
		<link>https://codeshell.io/archives/397</link>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Tue, 08 Jan 2019 10:28:02 +0000</pubDate>
				<category><![CDATA[网络]]></category>
		<category><![CDATA[tcp/ip]]></category>
		<guid isPermaLink="false">https://blog.lcodelite.com/?p=397</guid>

					<description><![CDATA[]]></description>
										<content:encoded><![CDATA[
<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="911" height="466" src="https://codeshell.io/wp-content/uploads/2023/05/networkPotocol.png" alt="" class="wp-image-554"/></figure>



<p></p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Go语言介绍</title>
		<link>https://codeshell.io/archives/340</link>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Fri, 14 Dec 2018 14:11:54 +0000</pubDate>
				<category><![CDATA[go语言学习]]></category>
		<category><![CDATA[go]]></category>
		<guid isPermaLink="false">https://blog.lcodelite.com/?p=340</guid>

					<description><![CDATA[Go语言的背景和要解决的问题 最近十年来，C/C++在计算领域没有很好得到发展，并没有新的系统编程语言出现。对开发程度和系统效率在很多情况下不能兼得。要么执行效...<p class="read-more"><a class="btn btn-default" href="https://codeshell.io/archives/340"> Read More<span class="screen-reader-text">  Read More</span></a></p>]]></description>
										<content:encoded><![CDATA[
<h2 class="wp-block-heading"><strong>Go语言的背景和要解决的问题</strong></h2>



<p>最近十年来，C/C++在计算领域没有很好得到发展，并没有新的系统编程语言出现。对开发程度和系统效率在很多情况下不能兼得。要么执行效率高，但低效的开发和编译，如C++；要么执行低效，但拥有有效的编译，如.NET、Java；所以需要一种拥有较高效的执行速度、编译速度和开发速度的编程语言，Go就横空出世了。</p>



<h2 class="wp-block-heading"><strong>Go的优势与劣势</strong></h2>



<ol class="wp-block-list"><li>可直接编译成机器码，不依赖其他库，glibc的版本有一定要求，部署就是扔一个文件上去就完成了。</li><li>静态类型语言，但是有动态语言的感觉，静态类型的语言就是可以在编译的时候检查出来隐藏的大多数问题，动态语言的感觉就是有很多的包可以使用，写起来的效率很高。</li><li>语言层面支持并发，这个就是Go最大的特色，天生的支持并发。</li><li>内置runtime，支持垃圾回收。</li><li>简单易学，Go语言的作者都有C的基因，那么Go自然而然就有了C的基因，那么Go关键字是25个，但是表达能力很强大，几乎支持大多数你在其他语言见过的特性：继承、重载、对象等。</li><li>丰富的标准库，Go目前已经内置了大量的库，特别是网络库非常强大。</li><li>内置强大的工具，Go语言里面内置了很多工具链，最好的应该是gofmt工具，自动化格式化代码，能够让团队review变得如此的简单，代码格式一模一样，想不一样都很困难。</li><li>跨平台编译，如果你写的Go代码不包含cgo，那么就可以做到window系统编译linux的应用，如何做到的呢？Go引用了plan9的代码，这就是不依赖系统的信息。</li><li>内嵌C支持，前面说了作者是C的作者，所以Go里面也可以直接包含c代码，利用现有的丰富的C库。</li></ol>



<h2 class="wp-block-heading">Go的应用场景</h2>



<ol class="wp-block-list"><li>服务器编程，以前你如果使用C或者C++做的那些事情，用Go来做很合适，例如处理日志、数据打包、虚拟机处理、文件系统等。</li><li>分布式系统，数据库代理器等。</li><li>网络编程，这一块目前应用最广，包括Web应用、API应用、下载应用。</li><li>内存数据库，前一段时间google开发的groupcache，couchbase的部分组件。</li><li>云平台，目前国外很多云平台在采用Go开发，CloudFoundy的部分组建，前VMare的技术总监自己出来搞的apcera云平台。</li></ol>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Go结构体函数一些小细节</title>
		<link>https://codeshell.io/archives/324</link>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Wed, 12 Dec 2018 09:29:50 +0000</pubDate>
				<category><![CDATA[go语言学习]]></category>
		<category><![CDATA[go]]></category>
		<category><![CDATA[struct]]></category>
		<category><![CDATA[结构体]]></category>
		<guid isPermaLink="false">https://blog.lcodelite.com/?p=324</guid>

					<description><![CDATA[在go中定义结构体函数的方式如下： 上面的setX函数的声明其实可以理解成这样 所以也可以声明个同类型的函数变量然后给它赋值]]></description>
										<content:encoded><![CDATA[
<p>在go中定义结构体函数的方式如下：</p>



<div class="wp-block-kevinbatdorf-code-block-pro" data-code-block-pro-font-family="" style="font-size:clamp(14px, .875rem, 21px);line-height:clamp(20px, 1.25rem, 30px);--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff"><svg xmlns="http://www.w3.org/2000/svg" width="54" height="14" viewBox="0 0 54 14"><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><circle cx="6" cy="6" r="6" fill="#FF5F56" stroke="#E0443E" stroke-width=".5"></circle><circle cx="26" cy="6" r="6" fill="#FFBD2E" stroke="#DEA123" stroke-width=".5"></circle><circle cx="46" cy="6" r="6" fill="#27C93F" stroke="#1AAB29" stroke-width=".5"></circle></g></svg></span><span role="button" tabindex="0" style="color:#d8dee9ff;display:none" aria-label="复制" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>type myStruct struct {
    x int
}

func (s *myStruct) setX(newValue int) {
    s.x = newValue
}</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki nord" style="background-color: #2e3440ff" tabindex="0"><code><span class="line"><span style="color: #81A1C1">type</span><span style="color: #D8DEE9FF"> myStruct </span><span style="color: #81A1C1">struct</span><span style="color: #D8DEE9FF"> </span><span style="color: #ECEFF4">{</span></span>
<span class="line"><span style="color: #D8DEE9FF">    x </span><span style="color: #81A1C1">int</span></span>
<span class="line"><span style="color: #ECEFF4">}</span></span>
<span class="line"></span>
<span class="line"><span style="color: #81A1C1">func</span><span style="color: #D8DEE9FF"> </span><span style="color: #ECEFF4">(</span><span style="color: #D8DEE9FF">s </span><span style="color: #81A1C1">*</span><span style="color: #D8DEE9FF">myStruct</span><span style="color: #ECEFF4">)</span><span style="color: #D8DEE9FF"> </span><span style="color: #88C0D0">setX</span><span style="color: #ECEFF4">(</span><span style="color: #D8DEE9FF">newValue </span><span style="color: #81A1C1">int</span><span style="color: #ECEFF4">)</span><span style="color: #D8DEE9FF"> </span><span style="color: #ECEFF4">{</span></span>
<span class="line"><span style="color: #D8DEE9FF">    </span><span style="color: #D8DEE9">s</span><span style="color: #ECEFF4">.</span><span style="color: #D8DEE9">x</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">=</span><span style="color: #D8DEE9FF"> newValue</span></span>
<span class="line"><span style="color: #ECEFF4">}</span></span></code></pre></div>



<p>上面的setX函数的声明其实可以理解成这样</p>



<div class="wp-block-kevinbatdorf-code-block-pro" data-code-block-pro-font-family="" style="font-size:clamp(14px, .875rem, 21px);line-height:clamp(20px, 1.25rem, 30px);--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff"><svg xmlns="http://www.w3.org/2000/svg" width="54" height="14" viewBox="0 0 54 14"><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><circle cx="6" cy="6" r="6" fill="#FF5F56" stroke="#E0443E" stroke-width=".5"></circle><circle cx="26" cy="6" r="6" fill="#FFBD2E" stroke="#DEA123" stroke-width=".5"></circle><circle cx="46" cy="6" r="6" fill="#27C93F" stroke="#1AAB29" stroke-width=".5"></circle></g></svg></span><span role="button" tabindex="0" style="color:#d8dee9ff;display:none" aria-label="复制" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>func (s *myStruct, newValue int)</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki nord" style="background-color: #2e3440ff" tabindex="0"><code><span class="line"><span style="color: #81A1C1">func</span><span style="color: #D8DEE9FF"> </span><span style="color: #ECEFF4">(</span><span style="color: #D8DEE9FF">s </span><span style="color: #81A1C1">*</span><span style="color: #D8DEE9FF">myStruct</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> newValue </span><span style="color: #81A1C1">int</span><span style="color: #ECEFF4">)</span></span></code></pre></div>



<p>所以也可以声明个同类型的函数变量然后给它赋值</p>



<div class="wp-block-kevinbatdorf-code-block-pro" data-code-block-pro-font-family="" style="font-size:clamp(14px, .875rem, 21px);line-height:clamp(20px, 1.25rem, 30px);--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff"><svg xmlns="http://www.w3.org/2000/svg" width="54" height="14" viewBox="0 0 54 14"><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><circle cx="6" cy="6" r="6" fill="#FF5F56" stroke="#E0443E" stroke-width=".5"></circle><circle cx="26" cy="6" r="6" fill="#FFBD2E" stroke="#DEA123" stroke-width=".5"></circle><circle cx="46" cy="6" r="6" fill="#27C93F" stroke="#1AAB29" stroke-width=".5"></circle></g></svg></span><span role="button" tabindex="0" style="color:#d8dee9ff;display:none" aria-label="复制" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>s := myStruct{5}
var mySetX func(s *myStruct, newValue int)
// 这里注意必须是(*myStruct).setX而不是myStruct.setX，因为声明部分是func(s *myStruct, newValue int)，所以可以把.setX前面那部分看成setX的第一个入参
mySetX = (*myStruct).setX
mySetX(&amp;s, 6)
fmt.Println(myS.x) // 输出6
// 注意这里不需要用(*myS).setX，因为显性调用函数编译器会自动对引用进行转换
myS.setX(7)
fmt.Println(myS.x) // 输出7</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki nord" style="background-color: #2e3440ff" tabindex="0"><code><span class="line"><span style="color: #D8DEE9">s</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">:=</span><span style="color: #D8DEE9FF"> myStruct</span><span style="color: #ECEFF4">{</span><span style="color: #B48EAD">5</span><span style="color: #ECEFF4">}</span></span>
<span class="line"><span style="color: #81A1C1">var</span><span style="color: #D8DEE9FF"> </span><span style="color: #D8DEE9">mySetX</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">func</span><span style="color: #ECEFF4">(</span><span style="color: #D8DEE9FF">s </span><span style="color: #81A1C1">*</span><span style="color: #D8DEE9FF">myStruct</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> newValue </span><span style="color: #81A1C1">int</span><span style="color: #ECEFF4">)</span></span>
<span class="line"><span style="color: #616E88">// 这里注意必须是(*myStruct).setX而不是myStruct.setX，因为声明部分是func(s *myStruct, newValue int)，所以可以把.setX前面那部分看成setX的第一个入参</span></span>
<span class="line"><span style="color: #D8DEE9">mySetX</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">=</span><span style="color: #D8DEE9FF"> </span><span style="color: #ECEFF4">(</span><span style="color: #81A1C1">*</span><span style="color: #D8DEE9FF">myStruct</span><span style="color: #ECEFF4">).</span><span style="color: #D8DEE9FF">setX</span></span>
<span class="line"><span style="color: #88C0D0">mySetX</span><span style="color: #ECEFF4">(</span><span style="color: #81A1C1">&amp;</span><span style="color: #D8DEE9FF">s</span><span style="color: #ECEFF4">,</span><span style="color: #D8DEE9FF"> </span><span style="color: #B48EAD">6</span><span style="color: #ECEFF4">)</span></span>
<span class="line"><span style="color: #D8DEE9FF">fmt</span><span style="color: #ECEFF4">.</span><span style="color: #88C0D0">Println</span><span style="color: #ECEFF4">(</span><span style="color: #D8DEE9FF">myS</span><span style="color: #ECEFF4">.</span><span style="color: #D8DEE9FF">x</span><span style="color: #ECEFF4">)</span><span style="color: #D8DEE9FF"> </span><span style="color: #616E88">// 输出6</span></span>
<span class="line"><span style="color: #616E88">// 注意这里不需要用(*myS).setX，因为显性调用函数编译器会自动对引用进行转换</span></span>
<span class="line"><span style="color: #D8DEE9FF">myS</span><span style="color: #ECEFF4">.</span><span style="color: #88C0D0">setX</span><span style="color: #ECEFF4">(</span><span style="color: #B48EAD">7</span><span style="color: #ECEFF4">)</span></span>
<span class="line"><span style="color: #D8DEE9FF">fmt</span><span style="color: #ECEFF4">.</span><span style="color: #88C0D0">Println</span><span style="color: #ECEFF4">(</span><span style="color: #D8DEE9FF">myS</span><span style="color: #ECEFF4">.</span><span style="color: #D8DEE9FF">x</span><span style="color: #ECEFF4">)</span><span style="color: #D8DEE9FF"> </span><span style="color: #616E88">// 输出7</span></span></code></pre></div>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Go对数组使用切片的细节</title>
		<link>https://codeshell.io/archives/319</link>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Mon, 10 Dec 2018 06:43:37 +0000</pubDate>
				<category><![CDATA[go语言学习]]></category>
		<category><![CDATA[go]]></category>
		<category><![CDATA[slice]]></category>
		<category><![CDATA[切片]]></category>
		<guid isPermaLink="false">https://blog.lcodelite.com/?p=319</guid>

					<description><![CDATA[go对一个数组使用切片操作时，会自动生成一个指向该数组的切片]]></description>
										<content:encoded><![CDATA[
<p>go对一个数组使用切片操作时，会自动生成一个指向该数组的切片</p>



<div class="wp-block-kevinbatdorf-code-block-pro" data-code-block-pro-font-family="" style="font-size:clamp(14px, .875rem, 21px);line-height:clamp(20px, 1.25rem, 30px);--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#2e3440ff"><svg xmlns="http://www.w3.org/2000/svg" width="54" height="14" viewBox="0 0 54 14"><g fill="none" fill-rule="evenodd" transform="translate(1 1)"><circle cx="6" cy="6" r="6" fill="#FF5F56" stroke="#E0443E" stroke-width=".5"></circle><circle cx="26" cy="6" r="6" fill="#FFBD2E" stroke="#DEA123" stroke-width=".5"></circle><circle cx="46" cy="6" r="6" fill="#27C93F" stroke="#1AAB29" stroke-width=".5"></circle></g></svg></span><span role="button" tabindex="0" style="color:#d8dee9ff;display:none" aria-label="复制" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>package main

import "fmt"

func setArray(s []int) {
    s&#91;0&#93; = 1
    s&#91;1&#93; = 2
}

// 函数内修改切片会导致数组变化，因为该切片指向的是数组地址
func main() {
    arr := &#91;5&#93;int{}
    setArray(arr&#91;:&#93;)
    fmt.Println(arr&#91;1&#93;)
}</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></span><pre class="shiki nord" style="background-color: #2e3440ff" tabindex="0"><code><span class="line"><span style="color: #81A1C1">package</span><span style="color: #D8DEE9FF"> main</span></span>
<span class="line"></span>
<span class="line"><span style="color: #81A1C1">import</span><span style="color: #D8DEE9FF"> </span><span style="color: #ECEFF4">&quot;</span><span style="color: #A3BE8C">fmt</span><span style="color: #ECEFF4">&quot;</span></span>
<span class="line"></span>
<span class="line"><span style="color: #81A1C1">func</span><span style="color: #D8DEE9FF"> </span><span style="color: #88C0D0">setArray</span><span style="color: #ECEFF4">(</span><span style="color: #D8DEE9FF">s </span><span style="color: #ECEFF4">[]</span><span style="color: #81A1C1">int</span><span style="color: #ECEFF4">)</span><span style="color: #D8DEE9FF"> </span><span style="color: #ECEFF4">{</span></span>
<span class="line"><span style="color: #D8DEE9FF">    s</span><span style="color: #ECEFF4">&#91;</span><span style="color: #B48EAD">0</span><span style="color: #ECEFF4">&#93;</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">=</span><span style="color: #D8DEE9FF"> </span><span style="color: #B48EAD">1</span></span>
<span class="line"><span style="color: #D8DEE9FF">    s</span><span style="color: #ECEFF4">&#91;</span><span style="color: #B48EAD">1</span><span style="color: #ECEFF4">&#93;</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">=</span><span style="color: #D8DEE9FF"> </span><span style="color: #B48EAD">2</span></span>
<span class="line"><span style="color: #ECEFF4">}</span></span>
<span class="line"></span>
<span class="line"><span style="color: #616E88">// 函数内修改切片会导致数组变化，因为该切片指向的是数组地址</span></span>
<span class="line"><span style="color: #81A1C1">func</span><span style="color: #D8DEE9FF"> </span><span style="color: #88C0D0">main</span><span style="color: #ECEFF4">()</span><span style="color: #D8DEE9FF"> </span><span style="color: #ECEFF4">{</span></span>
<span class="line"><span style="color: #D8DEE9FF">    </span><span style="color: #D8DEE9">arr</span><span style="color: #D8DEE9FF"> </span><span style="color: #81A1C1">:=</span><span style="color: #D8DEE9FF"> </span><span style="color: #ECEFF4">&#91;</span><span style="color: #B48EAD">5</span><span style="color: #ECEFF4">&#93;</span><span style="color: #81A1C1">int</span><span style="color: #ECEFF4">{}</span></span>
<span class="line"><span style="color: #D8DEE9FF">    </span><span style="color: #88C0D0">setArray</span><span style="color: #ECEFF4">(</span><span style="color: #D8DEE9FF">arr</span><span style="color: #ECEFF4">&#91;:&#93;)</span></span>
<span class="line"><span style="color: #D8DEE9FF">    fmt</span><span style="color: #ECEFF4">.</span><span style="color: #88C0D0">Println</span><span style="color: #ECEFF4">(</span><span style="color: #D8DEE9FF">arr</span><span style="color: #ECEFF4">&#91;</span><span style="color: #B48EAD">1</span><span style="color: #ECEFF4">&#93;)</span></span>
<span class="line"><span style="color: #ECEFF4">}</span></span></code></pre></div>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
