Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #6446

Re: GIL in alternative implementations

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!selfless.tophat.at!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <dan.kluev@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.006
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'cpython': 0.07; 'python': 0.08; 'concurrency': 0.09; 'def': 0.12; 'containers': 0.16; 'margin.': 0.16; 'pypy': 0.16; 'subject:GIL': 0.16; 'subject:alternative': 0.16; 't.start()': 0.16; 'threading': 0.16; 'threads:': 0.16; 'header:In-Reply-To:1': 0.21; 'java': 0.21; "aren't": 0.22; 'gil': 0.23; 'received:209.85.210.174': 0.23; 'received:mail-iy0-f174.google.com': 0.23; 'pass': 0.27; "i'm": 0.27; 'message-id:@mail.gmail.com': 0.28; '.net': 0.29; 'import': 0.29; 'elements': 0.29; 'class': 0.29; 'code,': 0.29; 'least': 0.30; 'know:': 0.30; 'threads': 0.30; 'to:addr:python-list': 0.33; 'thinking': 0.34; 'daniel': 0.34; 'received:google.com': 0.37; 'received:209.85': 0.37; 'thread': 0.37; 'but': 0.38; 'matters': 0.38; 'subject:: ': 0.38; 'some': 0.38; "i'd": 0.39; 'received:209': 0.39; 'either': 0.39; 'to:addr:python.org': 0.39; 'getting': 0.40; 'best': 0.60; 'corrupted': 0.84
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:date :message-id:subject:from:to:content-type; bh=yfediMNHpsNMK41Y9i8lBmOh19j1F5ZImnNRy1u39WU=; b=aQYn2FE+6EG9D+juqnOFtOSjZa3ZuY+useHc0WJQprolOQR1uhCeMHkutEIf1fJqv5 C3RtR78frTfHeyiI4TtK68z+QSE5qqmBc9YL0CFpyto2NIhpN6YqXgBU3fqq308XWgk5 ibB1A3vbNyWjIMKXMvxNqdq6yBR4dFHqd/27A=
DomainKey-Signature a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; b=N+pTN/B8a685jZttdwv9XjNwKzXGq0ZCq7t0suJH00XBPWjYGtUJ9A30Jl46zqLGUl 3DwqS4ZyQcSJBN8ntTH6Gy6tKJfKZ+EESgUzuurr5K9Hlk0C/9oaWAnJXcVkGXtx+931 c532mxiFXOtbhRtagNudaspqE+9WnLj1Ukc5M=
MIME-Version 1.0
In-Reply-To <4DE015EA.4040600@gmail.com>
References <4DE015EA.4040600@gmail.com>
Date Sat, 28 May 2011 13:06:43 +1100
Subject Re: GIL in alternative implementations
From Daniel Kluev <dan.kluev@gmail.com>
To python-list@python.org
Content-Type text/plain; charset=ISO-8859-1
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.2185.1306548406.9059.python-list@python.org> (permalink)
Lines 47
NNTP-Posting-Host 82.94.164.166
X-Trace 1306548406 news.xs4all.nl 49042 [::ffff:82.94.164.166]:59924
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:6446

Show key headers only | View raw


> So I'd like to know: how do these other implementations handle concurrency
> matters for their primitive types, and prevent them from getting corrupted
> in multithreaded programs (if they do) ? I'm not only thinking about python
> types, but also primitive containers and types used in .Net and Java VMs,
> which aren't atomic elements either at an assembly-level point of view.

Well, they definitely have some shortcomings:

test.py:

from threading import Thread
class X(object):
    pass
obj = X()
obj.x = 0

def f(*args):
   for i in range(10000):
       obj.x += 1

threads = []
for i in range(100):
    t = Thread(target=f)
    threads.append(t)
    t.start()

for t in threads:
    while t.isAlive():
        t.join(1)

print(obj.x)

> python test.py
1000000
> pypy test.py
1000000
> jython-2.5 test.py
19217
> ipy test.py
59040

Not that this thing is reasonable to do in real code, but cpython and
other implementations with GIL at least give you some safety margin.

-- 
With best regards,
Daniel Kluev

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Re: GIL in alternative implementations Daniel Kluev <dan.kluev@gmail.com> - 2011-05-28 13:06 +1100
  Re: GIL in alternative implementations Marc Christiansen <usenet@solar-empire.de> - 2011-05-28 11:55 +0200
    Re: GIL in alternative implementations Wolfgang Rohdewald <wolfgang@rohdewald.de> - 2011-05-28 13:16 +0200
  Re: GIL in alternative implementations John Nagle <nagle@animats.com> - 2011-05-28 09:39 -0700
    Re: GIL in alternative implementations Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-05-28 17:05 +0000
      Re: GIL in alternative implementations "Gabriel Genellina" <gagsl-py2@yahoo.com.ar> - 2011-06-07 01:03 -0300
        Re: GIL in alternative implementations Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-06-07 07:09 +0000
        Re: GIL in alternative implementations Jean-Paul Calderone <calderone.jeanpaul@gmail.com> - 2011-06-07 05:07 -0700

csiph-web