Path: csiph.com!usenet.pasdenom.info!gegeweb.org!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'output': 0.05; 'correct.': 0.07; 'merging': 0.09; 'messing': 0.09; 'output,': 0.09; 'sure,': 0.09; 'trailing': 0.09; 'cc:addr:python-list': 0.11; '24,': 0.16; 'blocks': 0.16; 'descriptors,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'happily': 0.16; 'malloc': 0.16; 'newline,': 0.16; 'sane': 0.16; 'subject:? - ': 0.16; 'subject:Pypy': 0.16; 'subject:threads': 0.16; 'underlying': 0.16; 'wrote:': 0.18; 'obviously': 0.18; 'feb': 0.22; 'input': 0.22; 'issue.': 0.22; 'cc:addr:python.org': 0.22; 'tend': 0.24; 'paul': 0.24; 'cc:2**0': 0.24; 'header:In-Reply-To:1': 0.27; 'resolution': 0.29; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; 'code': 0.31; 'lines': 0.31; 'fine,': 0.31; 'file': 0.32; 'probably': 0.32; 'another': 0.32; 'quite': 0.32; 'text': 0.33; 'problem': 0.35; "can't": 0.35; 'problem.': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'subject:?': 0.36; 'should': 0.36; 'pm,': 0.38; 'sure': 0.39; "you're": 0.61; 'making': 0.63; '(that': 0.65; 'between': 0.67; '2015': 0.84; 'actually,': 0.84; 'absolutely': 0.87; 'to:none': 0.92; 'subject:Are': 0.93 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=czSGB40qcu+3sN3/loKKZ1PXutWe5W0eQWCR8Y0QtrE=; b=I4+5BPBSJtraeKtib/5DhmvTHO9EXI1I9rpB901Ujb84SeXzCLVxHBI/m0tLjGmysH VZK6mcJnFocj+Mc+QLHim263pIU209fMWD3wIeohJEJOLfPFQ42waFhloUw6f+aza/S5 wuDE+zh6KCuqh0vaEh1+Qp5ciUB+9RNfyKHflLkgn2JBa+1wzBiQXGq3jFAG6cWmQWIA DKIT7xlCciNOds5WXskbcZ4Gs0rgNXp/cgJHAT0Pmt6CjEEglnHcuqOl6tbMcva6HeD9 jl7M7XOZbhxXFOUkxH5miurUWivPSnSR0oCLFU+JAFs+wTLO4tZDgDNMRDk7MDBbMDq7 6+SA== MIME-Version: 1.0 X-Received: by 10.50.114.4 with SMTP id jc4mr17872598igb.14.1424757420081; Mon, 23 Feb 2015 21:57:00 -0800 (PST) In-Reply-To: <87lhjnang1.fsf@jester.gateway.pace.com> References: <87fv9xdb22.fsf@jester.gateway.pace.com> <54ea7ff4$0$12983$c3e8da3$5496439d@news.astraweb.com> <87zj85bcyu.fsf@jester.gateway.pace.com> <87lhjpb89i.fsf@jester.gateway.pace.com> <87h9udb1eq.fsf@jester.gateway.pace.com> <87bnkkb22u.fsf@jester.gateway.pace.com> <87lhjnang1.fsf@jester.gateway.pace.com> Date: Tue, 24 Feb 2015 16:57:00 +1100 Subject: Re: Are threads bad? - was: Future of Pypy? From: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 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: 23 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1424757423 news.xs4all.nl 2858 [2001:888:2000:d::a6]:42137 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:86297 On Tue, Feb 24, 2015 at 4:27 PM, Paul Rubin wrote: >> Sure, your code might not be making any mutations (that you know of), >> but malloc definitely is [1], and that's just the tip of the iceberg. >> Other things like buffers for stdin and stdout, DNS resolution etc. >> all have the same issue. > > Re stdin/stdout: obviously you can't have > multiple threads messing with the same fd's; that's the same thing as > data sharing. Actually, you can quite happily have multiple threads messing with the underlying file descriptors, that's not a problem. (Though you will tend to get interleaved output. But if you always produce output in single blocks of text that each contain one line with a trailing newline, you should see interleaved lines that are each individually correct. I'm also not sure of any sane way to multiplex stdin - merging output from multiple threads is fine, but dividing input between multiple threads is messy.) The problem is *buffers* for stdin and stdout, where you have to be absolutely sure that you're not trampling all over another thread's data structures. If you unbuffer your output, it's probably going to be thread-safe. ChrisA