<story><title>Python stands to lose its GIL, and gain a lot of speed</title><url>https://www.infoworld.com/article/3637073/python-stands-to-lose-its-gil-and-gain-a-lot-of-speed.html</url></story><parent_chain><item><author>chacham15</author><text>There are certain classes of errors that it prevents. E.g:&lt;p&gt;Thread1:
a = 0xFFFFFFFF00000000&lt;p&gt;Thread2:
a = 0x00000000FFFFFFFF&lt;p&gt;One might think that the two possible values of a if those are run concurrently are 0xFFFFFFFF00000000 and 0x00000000FFFFFFFF. But actually 0x0000000000000000 
 and 0xFFFFFFFFFFFFFFFF are also possible because the load itself isnt atomic.&lt;p&gt;The GIL (AFAICT) will prevent the latter two possibilities.</text></item><item><author>avianlyric</author><text>I don’t see how the GIL makes writing thread safe software any easier. The GIL might prevent two Python threads executing simultaneously, but it doesn’t change the fact that a Python thread can be preempted, meaning your global state can change at any point during execution without warning.&lt;p&gt;Most of the issues with multi-threading come from concurrency, not parallelism. The GIL allows concurrency, you just don’t get any of the advantages of parallelism, which is normally the reason for putting up with the complexity concurrency creates.</text></item><item><author>dleslie</author><text>I wonder how many folks think they&amp;#x27;re writing thread safe software with ease, and are unaware that they are leaning on the GIL?&lt;p&gt;Could be that the impact of this change is far broader than just a few key libraries.</text></item></parent_chain><comment><author>adrian_b</author><text>Most CPUs guarantee that aligned loads and stores up to the register size, i.e. now usually up to 64-bit, are atomic.&lt;p&gt;The compilers also take care to align most variables.&lt;p&gt;So while your scenario is not impossible, it would take some effort to force &amp;quot;a&amp;quot; to be not aligned, e.g. by being a member in a structure with inefficient layout.&lt;p&gt;Normally in a multithreaded program all shared variables should be aligned, which would guarantee atomic loads and stores.</text></comment>
<story><title>Python stands to lose its GIL, and gain a lot of speed</title><url>https://www.infoworld.com/article/3637073/python-stands-to-lose-its-gil-and-gain-a-lot-of-speed.html</url></story><parent_chain><item><author>chacham15</author><text>There are certain classes of errors that it prevents. E.g:&lt;p&gt;Thread1:
a = 0xFFFFFFFF00000000&lt;p&gt;Thread2:
a = 0x00000000FFFFFFFF&lt;p&gt;One might think that the two possible values of a if those are run concurrently are 0xFFFFFFFF00000000 and 0x00000000FFFFFFFF. But actually 0x0000000000000000 
 and 0xFFFFFFFFFFFFFFFF are also possible because the load itself isnt atomic.&lt;p&gt;The GIL (AFAICT) will prevent the latter two possibilities.</text></item><item><author>avianlyric</author><text>I don’t see how the GIL makes writing thread safe software any easier. The GIL might prevent two Python threads executing simultaneously, but it doesn’t change the fact that a Python thread can be preempted, meaning your global state can change at any point during execution without warning.&lt;p&gt;Most of the issues with multi-threading come from concurrency, not parallelism. The GIL allows concurrency, you just don’t get any of the advantages of parallelism, which is normally the reason for putting up with the complexity concurrency creates.</text></item><item><author>dleslie</author><text>I wonder how many folks think they&amp;#x27;re writing thread safe software with ease, and are unaware that they are leaning on the GIL?&lt;p&gt;Could be that the impact of this change is far broader than just a few key libraries.</text></item></parent_chain><comment><author>ignoramous</author><text>Related: &lt;i&gt;Symmetric Multi-Processor primer for Android&lt;/i&gt;, &lt;a href=&quot;https:&amp;#x2F;&amp;#x2F;developer.android.com&amp;#x2F;training&amp;#x2F;articles&amp;#x2F;smp&quot; rel=&quot;nofollow&quot;&gt;https:&amp;#x2F;&amp;#x2F;developer.android.com&amp;#x2F;training&amp;#x2F;articles&amp;#x2F;smp&lt;/a&gt; (although for Android&amp;#x2F;ARM, it makes for a pretty good read on the topic).</text></comment>