From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Jan Wielkiewicz Newsgroups: gmane.lisp.guile.user Subject: Re: GOOPS and fibers - need help understanding what's wrong, bug in fibers/guile? Date: Fri, 24 Jul 2020 18:19:24 +0200 Message-ID: <20200724181924.6667ef10@interia.pl> References: <20200722015653.630db7f9@interia.pl> <20200722125420.df6acee9612d35be10145c3c@gmail.com> <20200722132814.ddafae7536dc479408a6513a@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="22974"; mail-complaints-to="usenet@ciao.gmane.io" Cc: guile-user@gnu.org To: Chris Vine Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Fri Jul 24 18:20:19 2020 Return-path: Envelope-to: guile-user@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jz0Ql-0005rh-B8 for guile-user@m.gmane-mx.org; Fri, 24 Jul 2020 18:20:19 +0200 Original-Received: from localhost ([::1]:48000 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jz0Qk-0007Kg-DT for guile-user@m.gmane-mx.org; Fri, 24 Jul 2020 12:20:18 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:49648) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jz0QB-00075A-M9 for guile-user@gnu.org; Fri, 24 Jul 2020 12:19:43 -0400 Original-Received: from smtpo.poczta.interia.pl ([217.74.65.156]:57898) by eggs.gnu.org with esmtps (TLS1.2:RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jz0Q8-0006aZ-3h for guile-user@gnu.org; Fri, 24 Jul 2020 12:19:43 -0400 X-Interia-R: Interia X-Interia-R-IP: 89.64.43.25 X-Interia-R-Helo: Original-Received: from localhost (89-64-43-25.dynamic.chello.pl [89.64.43.25]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by poczta.interia.pl (INTERIA.PL) with ESMTPSA; Fri, 24 Jul 2020 18:19:33 +0200 (CEST) In-Reply-To: <20200722132814.ddafae7536dc479408a6513a@gmail.com> X-Mailer: Claws Mail 3.17.6 (GTK+ 2.24.32; x86_64-unknown-linux-gnu) X-Interia-Antivirus: OK DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=interia.pl; s=biztos; t=1595607574; bh=p6tlqkXkz1fGnmywTW5XX1WiD55A6soUA6WWIQOx6sQ=; h=X-Interia-R:X-Interia-R-IP:X-Interia-R-Helo:Date:From:To:Cc: Subject:Message-ID:In-Reply-To:References:X-Mailer:MIME-Version: Content-Type:Content-Transfer-Encoding:X-Interia-Antivirus; b=MjG9GZCkjRkfWRv9DEu0qsz8Fb7f3MpxcKnMpZS2nW691Nf1iRSe3s7+se5z/sXnY dO63l86Sb6AF4e42c3xo59fsgNYvyb+npaakZW3p7IAiwdlLrRGNali39a8m6V2qpc SkR7qwV/uqHNeWcdCYqA8Oxc8eATGqJGVXi/gYkk= Received-SPF: pass client-ip=217.74.65.156; envelope-from=tona_kosmicznego_smiecia@interia.pl; helo=smtpo.poczta.interia.pl X-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/24 12:19:34 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x (no timestamps) [generic] X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Original-Sender: "guile-user" Xref: news.gmane.io gmane.lisp.guile.user:16741 Archived-At: Hello, Dnia 2020-07-22, o godz. 13:28:14 Chris Vine napisa=C5=82(a): > On further reflection I am not sure if it did used to work with > guile-2.2. I think it may be a bug in the manual after all. This > works OK: >=20 > (display (run-fibers > (lambda () > (let ((channel (make-channel))) > (spawn-fiber > (lambda () > (sleep 1) ;; do some work > (put-message channel "hello world"))) > (simple-format #t "~a~%" (get-message channel)) > "finished\n")))) >=20 This one just worked, I don't know why, even without "display". Something is buggy it seems. > The point about: >=20 > (run-fibers > (lambda () (spawn-fiber > (lambda () > (set! v "Set") > (display "hey!\n"))))) >=20 > is that spawn-fiber, and so init-thunk, will return straigntaway with > a new fiber object. >=20 > So I suspect setting #:drain? to #t will resolve your problem. #:drain solved the problem and I also managed to make my code work. > It might be worth reporting the bug in the manual as an issue on the > github repository (assuming the above is correct). >=20 Yes, I'll report it. Thanks for helping me! Posting my working code, so someone wanting to mix GOOPS with fibers will have a working example: (define-module (blocks block) #:use-module (fibers) #:use-module (fibers channels) #:use-module (oop goops) #:use-module (ice-9 match) #:use-module (srfi srfi-9) ;; records #:export ( connect-peers send-message handle-message main p1 p2 get-buffer)) (define-class () (input #:init-form '() #:getter get-input #:setter set-input #:init-keyword #:input) (output #:init-form '() #:getter get-output #:setter set-output #:init-keyword #:output) (buffer #:init-value '() #:setter set-buffer #:getter get-buffer)) ;; Only connection, no messaging started. (define-method (connect-peers (p1 ) (p2 )) (let ((p1-p2 (make-channel)) ;; p1 to p2 (p2-p1 (make-channel))) ;; p2 to p1 (set-input p1 p2-p1) (set-output p1 p1-p2) (set-input p2 p1-p2) (set-output p2 p2-p1))) (define-method (send-message (p ) msg) (spawn-fiber (lambda () (put-message (get-output p) msg)))) (define-method (handle-message (p )) (spawn-fiber (lambda () (let loop () (define msg (get-message (get-input p))) (match (pk msg) ('ping (send-message p 'pong)) ('pong (send-message p 'ping))) (loop))))) (define (main) (define p1 (make )) (define p2 (make )) (connect-peers p1 p2) (run-fibers (lambda () (handle-message p1) (handle-message p2) (send-message p1 'ping)) #:drain? #t)) (main) --- Jan Wielkiewicz