From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Nic Ferrier Newsgroups: gmane.emacs.devel Subject: Re: Threads in emacs implementation Date: Wed, 08 Jun 2005 23:26:02 +0100 Message-ID: <87mzq0a3k5.fsf@kanga.tapsellferrier.co.uk> References: <6dbd4d0005060619227dd41364@mail.gmail.com> <87vf4oaft8.fsf@zemdatav.stor.no-ip.org> <87vf4oaao5.fsf@kanga.tapsellferrier.co.uk> <87ll5ka5j7.fsf@zemdatav.stor.no-ip.org> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1118269791 17575 80.91.229.2 (8 Jun 2005 22:29:51 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Wed, 8 Jun 2005 22:29:51 +0000 (UTC) Cc: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Jun 09 00:29:43 2005 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1Dg92L-0004eq-Pu for ged-emacs-devel@m.gmane.org; Thu, 09 Jun 2005 00:28:38 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Dg999-0004wF-BB for ged-emacs-devel@m.gmane.org; Wed, 08 Jun 2005 18:35:39 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Dg98i-0004ri-Vi for emacs-devel@gnu.org; Wed, 08 Jun 2005 18:35:14 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Dg98e-0004pP-FN for emacs-devel@gnu.org; Wed, 08 Jun 2005 18:35:08 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Dg98d-0004op-Qy for emacs-devel@gnu.org; Wed, 08 Jun 2005 18:35:07 -0400 Original-Received: from [80.168.156.78] (helo=owls-tree.tapsellferrier.co.uk) by monty-python.gnu.org with esmtp (TLS-1.0:RSA_AES_128_CBC_SHA:16) (Exim 4.34) id 1Dg95U-00089d-Sx for emacs-devel@gnu.org; Wed, 08 Jun 2005 18:31:53 -0400 Original-Received: from [80.168.156.68] (helo=kanga) by owls-tree.tapsellferrier.co.uk with esmtp (Exim 4.50 #1 (Debian)) id 1Dg8zK-00073P-82; Wed, 08 Jun 2005 23:25:30 +0100 Original-Received: from nferrier by kanga with local (Exim 4.44) id 1Dg8zs-0004Zq-3q; Wed, 08 Jun 2005 23:26:04 +0100 Original-To: Magnus Henoch In-Reply-To: <87ll5ka5j7.fsf@zemdatav.stor.no-ip.org> (Magnus Henoch's message of "Wed, 08 Jun 2005 23:43:24 +0200") X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:38380 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:38380 Magnus Henoch writes: > Nic Ferrier writes: > >> We don't need threads in elisp. Just more asynchronous network >> implementations. > > Good point. > > What is the best way to send a large amount of data to a network > connection in the background? You could send a chunk at a time with > process-send-string and then recurse with run-with-idle-timer, but it > seems that this will either block the UI or cause unnecessarily slow > transfer unless the chunk size and the delay are right. How about putting the data in a buffer and using: process-send-region In respect of sending lots of data, the same problem applies when using either threads or async. Consider the example of the text of the play The Tempest to a network process. The user can kill the buffer, alter the buffer, delete bits from the buffer, all while the transfer is going on. So the only way to achieve this is to lock the buffer first. >> Anyway, async code is so much more fun to write than threaded >> code. Threads are for beginners. > > Can you elaborate? I don't see how > > (defun foo-1 () > (send-request-with-callback 'foo-2)) > > (defun foo-2 (response) > (do-something response)) > > is more fun to write than: > > (defun foo () > (let ((response (send-request-and-get-response))) > (do-something response))) I was trying to be amusing. Asynchronous code is much harder to write than threaded code, hence threaded code is for beginners. Nic