From owner-freebsd-hackers@FreeBSD.ORG Tue Nov 16 16:33:50 2010 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 59A6F106566B for ; Tue, 16 Nov 2010 16:33:50 +0000 (UTC) (envelope-from joerg@britannica.bec.de) Received: from www.sonnenberger.org (www.sonnenberger.org [92.79.50.50]) by mx1.freebsd.org (Postfix) with ESMTP id C17558FC0A for ; Tue, 16 Nov 2010 16:33:49 +0000 (UTC) Received: from britannica.bec.de (www.sonnenberger.org [192.168.1.10]) by www.sonnenberger.org (Postfix) with ESMTP id 3A1F96669E for ; Tue, 16 Nov 2010 17:33:48 +0100 (CET) Received: by britannica.bec.de (Postfix, from userid 1000) id EBE5E116D6D; Tue, 16 Nov 2010 17:33:54 +0100 (CET) Date: Tue, 16 Nov 2010 17:33:54 +0100 From: Joerg Sonnenberger To: freebsd-hackers@freebsd.org Message-ID: <20101116163354.GA4720@britannica.bec.de> Mail-Followup-To: freebsd-hackers@freebsd.org References: <20101116151903.GA2361@britannica.bec.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) Subject: Re: Network socket concurrency (userland) X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 16 Nov 2010 16:33:50 -0000 On Tue, Nov 16, 2010 at 04:51:04PM +0100, Ivan Voras wrote: > On 11/16/10 16:19, Joerg Sonnenberger wrote: > >On Tue, Nov 16, 2010 at 03:37:59PM +0100, Ivan Voras wrote: > >>Are there any standard-defined guarantees for TCP network sockets > >>used by multiple threads to do IO on them? > > > >System calls are atomic relative to each other. They may be partially > >executed from the perspective of a remote system, e.g. due to > >segmentation, but one system call will finish before the next call of > >the same category is started. > > It seems to me that with a multithreaded kernel and multithreaded > userland that cannot really be guaranteed in general (and really > should not be guaranteed for performance reasons), but maybe it's > true for e.g. sockets if they are protected by a mutex or two within > the kernel? Of course it can be guaranteed. There are a few tricky bits like writing to a file with O_APPEND, but for sockets it is essentially all about taking a mutex before changes the socket buffer. > >>Specifically, will multiple write() or send() calls on the same > >>socket execute serially (i.e. not interfere with each other) and > >>blocking (until completion) even for large buffer sizes? What about > >>read() / recv()? > > > >All write operations are serialised against each other, just like all > >read operations are serialised against. > > To what degree is such serialization standardized (by POSIX?)? It is written somewhere, I forget where and can't find it right now :) Joerg