unofficial mirror of bug-guile@gnu.org 
 help / color / mirror / Atom feed
From: Robert Marlow <bobstopper@australispro.com.au>
Subject: Thread + Socket + Pipes Bug?
Date: 07 Aug 2003 15:58:10 +0800	[thread overview]
Message-ID: <1060243090.29489.46.camel@helicon> (raw)

[-- Attachment #1: Type: text/plain, Size: 1084 bytes --]

Hi

I've been spending ages on this bug and can't figure it out. I'm pretty
sure it's not a bug in something I've done so I'm submitting it here as
a possible guile bug. If it's not a bug in guile, many apologies but
please let me know what's gone wrong. 

I've attached two trimmed-down scripts which reproduce the bug. If you
place them in the same directory and run buggy.scm then you should be
able to connect to tcp port 6008 and start dumping data. The bug occurs
when you do this, crashing with an error as follows:

ERROR: In procedure select:
ERROR: Bad file descriptor

In my playing around I seem to have narrowed it down to being caused by
select working on one thread and a pipe being written to on another
thread. I couldn't determine much more than that. I do know the bug
occurs on both Solaris and GNU/Linux.

I hate to be whiney but my progress here at work is pretty well at a
standstill until either this bug is resolved or I dump guile and settle
for something like perl (which I really, really don't want to do). So
please help.


-- 
Regards,

Robert Marlow




[-- Attachment #2: buggy.scm --]
[-- Type: text/x-scheme, Size: 1811 bytes --]

#!/usr/bin/guile \
-e main -s
!#

(use-modules (ice-9 threads)
             (ice-9 popen))

(define mutex (make-mutex))
(define message-ready (make-condition-variable))

(define message "")

(define (main args)
  (begin-thread (thread))
  (begin-thread (thread))
  (begin-thread (thread))
  (begin-thread (thread))
  (begin-thread (thread))
  (let ((sock #f)
        (fileno #f))
    (lock-mutex mutex)
    (set! sock (socket AF_INET SOCK_STREAM 0))
    (unlock-mutex mutex)
    (bind sock AF_INET INADDR_ANY 6008)
    (listen sock 5)
    (while
     #t
     (let* ((client-connection (accept/no-block sock))
            (client-details (cdr client-connection))
            (client (car client-connection)))
       (lock-mutex mutex)
       (do ((line (read-line client) (read-line client)))
           ((eof-object? line)
            (shutdown client 2))
         (set! message (string-append message line "\n")))
       (signal-condition-variable message-ready)
       (unlock-mutex mutex)))))


(define (thread)
  (while
   #t
   
   (lock-mutex mutex)
   (if (not (> (string-length message) 0))
       (wait-condition-variable message-ready mutex)
       (let ((outgoing message))
         (set! message "")
         (unlock-mutex mutex)
         (piper outgoing)))
   (unlock-mutex mutex)))


(define (piper message)
  (lock-mutex mutex)
  (let ((pipe (open-output-pipe "./buggy-companion.scm")))
    (display message pipe)
    (close-port pipe))
  (unlock-mutex mutex))
    



(define (accept/no-block s)
  (if (null? (car (select (vector s) '() '()))) ; This select complains
      (accept/no-block s)
      (let ((client #f))
        (lock-mutex mutex)
        (set! client (accept s))
        (unlock-mutex mutex)
        client)))

[-- Attachment #3: buggy-companion.scm --]
[-- Type: text/x-scheme, Size: 242 bytes --]

#!/usr/bin/guile \
-e main -s
!#

(define (main args)
  (let ((str ""))
    (do ((line (read-line) (read-line)))
	((eof-object? line))
      (set! str (string-append str line "\n")))
     (sleep 10)
     (display str)))
	    
    

[-- Attachment #4: Type: text/plain, Size: 136 bytes --]

_______________________________________________
Bug-guile mailing list
Bug-guile@gnu.org
http://mail.gnu.org/mailman/listinfo/bug-guile

             reply	other threads:[~2003-08-07  7:58 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-08-07  7:58 Robert Marlow [this message]
     [not found] ` <m3adalb1ni.fsf@laruns.ossau.uklinux.net>
2003-08-08  1:09   ` Thread + Socket + Pipes Bug? Robert Marlow
2003-08-10 21:19     ` Neil Jerram
2003-08-11 10:02       ` bobstopper
2003-08-12 23:06         ` Neil Jerram
2003-08-14 10:43           ` Robert Marlow
2003-08-15 22:35             ` Neil Jerram
2003-08-14 14:08           ` Robert Marlow

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1060243090.29489.46.camel@helicon \
    --to=bobstopper@australispro.com.au \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).