Path: csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.017 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'cpython': 0.05; 'interpreter': 0.05; 'correct.': 0.07; 'linux,': 0.07; 'permitted': 0.07; 'counting': 0.09; 'objects,': 0.09; 'works.': 0.09; 'runs': 0.10; 'python': 0.11; 'concurrency,': 0.16; 'hp- ux,': 0.16; 'mechanism.': 0.16; 'subject:recursion': 0.16; 'underlying': 0.16; 'url:dabeaz': 0.16; 'variables,': 0.16; 'prevent': 0.16; 'wrote:': 0.18; 'seems': 0.21; 'subject:problem': 0.24; 'performing': 0.26; 'header:In-Reply-To:1': 0.27; 'said,': 0.30; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; 'that.': 0.31; 'factor': 0.31; 'os,': 0.31; "they'll": 0.31; 'though.': 0.31; 'probably': 0.32; 'run': 0.32; 'worked': 0.33; 'url:python': 0.33; 'running': 0.33; 'actual': 0.34; 'at:': 0.34; 'sense': 0.34; 'subject:the': 0.34; 'problem': 0.35; 'basic': 0.35; "can't": 0.35; 'tool': 0.35; 'equal': 0.35; 'objects': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'described': 0.36; 'object,': 0.36; 'opposed': 0.36; 'doing': 0.36; 'should': 0.36; 'example,': 0.37; 'wrong': 0.37; 'two': 0.37; 'performance': 0.37; 'being': 0.38; 'e.g.': 0.38; 'same.': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'anything': 0.39; 'expensive': 0.39; 'reported': 0.39; 'to:addr:python.org': 0.39; 'called': 0.40; 'release': 0.40; 'how': 0.40; 'is.': 0.60; 'new': 0.61; 'complete': 0.62; 'such': 0.63; 'more': 0.64; 'due': 0.66; 'believe': 0.68; 'url:pdf': 0.68; '26,': 0.68; 'default': 0.69; 'potentially': 0.81; 'counts': 0.83; 'atomic': 0.84; 'describes': 0.84; '2013': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=Jd+uBkJis70LJjNbfPPPQfmBm/klG/EB2+CUP4mKgQw=; b=lfEacSMsdLCyfUGHww31J3W14Kf+akSbbkfhG6+QlbcKxf+cH41F1zGeVO2+J8qJpM yj4LbxyIsBIZ6fx9EuLnKSTnFUgWSHJnMsMswGAlBYcOAsH1MG+KJHgDaGOAOp8tsawc MhiEZOyCW4MxctzuKzxQouski6FSMYKPOXUxSqeLaMfn6O6N0Cd3pRClm1lgRBhXbDqa 23q1l/YFjZpfZxba4ks1LB6R8yed2a7K0EMbb59TFasah38w/EzzRpXfRONoVPBH9LpI VQtbTyCJ8UhRWozFuPp3MBftbuPLS60X6SZKScz+zvKIJxwu1i7cL9/1t89SLpvS8PnQ l9mA== X-Received: by 10.68.125.227 with SMTP id mt3mr5596275pbb.153.1369634884464; Sun, 26 May 2013 23:08:04 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: <9890fd93-fd9b-4865-a01e-4cd1d558d5fc@w15g2000vbn.googlegroups.com> References: <55942e65-e4a5-45fc-b2fc-ceb4020959dd@k4g2000vba.googlegroups.com> <074eac8a-1bc4-4fe0-afa9-1f52405f81d5@k3g2000vbn.googlegroups.com> <9890fd93-fd9b-4865-a01e-4cd1d558d5fc@w15g2000vbn.googlegroups.com> From: Ian Kelly Date: Mon, 27 May 2013 00:07:23 -0600 Subject: Re: Solving the problem of mutual recursion To: Python Content-Type: text/plain; charset=ISO-8859-1 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 43 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1369634888 news.xs4all.nl 15971 [2001:888:2000:d::a6]:55996 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:46170 On Sun, May 26, 2013 at 10:36 PM, Peter Brooks wrote: > This makes complete sense - any atomic action should be atomic, so two > threads can't be doing it at the same time. They can be doing anything > else though. > > If two threads create a new object at the same time, for example, > there's potentially the problem that they'll get the same space, so > the object will be owned by both. To prevent this, the new object call > should be run in only one thread. > > If you have two objects running their methods on their own local > variables, then there's no potential for conflict, so there's no need > for them to be blocked. That's not the way it works. The CPython interpreter always runs with the GIL held; the alternative would be to have individual mutex locks on every Python object, which is expensive for performance due to the reference counting mechanism. Python functions can't release the GIL. C functions that are called from the interpreter *can* release the GIL to allow concurrency, but are only permitted to do so as long as they're not working with Python objects, e.g. waiting on I/O or performing a long calculation on C data. There are some more detailed slides on how the GIL works at: http://www.dabeaz.com/python/UnderstandingGIL.pdf Note that the description in Part 1 describes how the GIL worked prior to Python 3.2. The new GIL is described in Part 4, but the basic underlying concept is the same. > This is an interesting subject.. There's nothing wrong with the tool > I'm using to report threads - 'Activity Monitor' is the standard > process monitor. It counts cores as 'CPUs', which seems perfectly > reasonable to me. As I said, other Unixes, such as HP-UX, do the same > thing. I have no problem with that. It's also the default in Linux, where I believe it is called "IRIX mode" (as opposed to "Solaris mode", where the difference is just a factor equal to the number of cores). What I was questioning was whether the actual number being reported was correct. If it's the standard tool for the OS, then it probably is.