unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* recv! and thread
@ 2006-03-01  5:01 William Xu
  2006-03-03 23:44 ` Kevin Ryde
  0 siblings, 1 reply; 5+ messages in thread
From: William Xu @ 2006-03-01  5:01 UTC (permalink / raw)


Hi people, 

I want to create a receiver thread for receiving incoming packets. While
when the thread is created, seems it becomes the main thread? the
original guile> prompt is gone. Here is what i did, 

(define receiver
  (lambda ()
    (let ((sock (socket PF_INET SOCK_DGRAM 0))
	  (buf (make-string 65536)))
      (display "receiver running...\n")
      (connect sock AF_INET (inet-aton "127.0.0.1") 8000)
      (recv! sock buf))))

guile> (make-thread receiver)
#<thread 828785888 (100ca238)>
guile> receiver running...

Any clues?

-- 
William


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: recv! and thread
  2006-03-01  5:01 recv! and thread William Xu
@ 2006-03-03 23:44 ` Kevin Ryde
  2006-03-04  2:11   ` William Xu
  0 siblings, 1 reply; 5+ messages in thread
From: Kevin Ryde @ 2006-03-03 23:44 UTC (permalink / raw)
  Cc: guile-user

William Xu <william.xwl@gmail.com> writes:
>
> the original guile> prompt is gone

I think it's just been printed over on the tty.  Try typing something,
it should be still there :-).


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: recv! and thread
  2006-03-03 23:44 ` Kevin Ryde
@ 2006-03-04  2:11   ` William Xu
  2006-03-07 20:56     ` Kevin Ryde
  0 siblings, 1 reply; 5+ messages in thread
From: William Xu @ 2006-03-04  2:11 UTC (permalink / raw)


Kevin Ryde <user42@zip.com.au> writes:

> William Xu <william.xwl@gmail.com> writes:
>>
>> the original guile> prompt is gone
>
> I think it's just been printed over on the tty.  Try typing something,
> it should be still there :-).

Does it work there? i have already tried that.. If it were other general
thread, typing something does have a response.

-- 
William


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: recv! and thread
  2006-03-04  2:11   ` William Xu
@ 2006-03-07 20:56     ` Kevin Ryde
  2006-03-10 19:41       ` William Xu
  0 siblings, 1 reply; 5+ messages in thread
From: Kevin Ryde @ 2006-03-07 20:56 UTC (permalink / raw)
  Cc: guile-user

William Xu <william.xwl@gmail.com> writes:
>
> i have already tried that..

Oh, I see, in 1.6 it's a bare recv() call, it doesn't cooperate with
the multi-threading.  Hmm.  Not sure if it's easy to fix that, it
works in 1.8 because pthreads takes care of all blocking.

As a workaround in 1.6 I think you can stick in a select call

	(select (list sock) '() '())

just before the recv!, to wait for sock to have data ready to read.
(When select blocks it cooperates with the multi-threading, letting
other threads run.)


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: recv! and thread
  2006-03-07 20:56     ` Kevin Ryde
@ 2006-03-10 19:41       ` William Xu
  0 siblings, 0 replies; 5+ messages in thread
From: William Xu @ 2006-03-10 19:41 UTC (permalink / raw)


Kevin Ryde <user42@zip.com.au> writes:

> William Xu <william.xwl@gmail.com> writes:
>>
>> i have already tried that..
>
> Oh, I see, in 1.6 it's a bare recv() call, it doesn't cooperate with
> the multi-threading.  Hmm.  Not sure if it's easy to fix that, it
> works in 1.8 because pthreads takes care of all blocking.

oh... but it was cvs guile. I also tried with 1.8, still no luck,
though. :( 

And you also don't have the slib problem? I guess it might be some
platform related issue then. (It's debian on an ibook here.)

> As a workaround in 1.6 I think you can stick in a select call
>
> 	(select (list sock) '() '())
>
> just before the recv!, to wait for sock to have data ready to read.
> (When select blocks it cooperates with the multi-threading, letting
> other threads run.)

This workaround works nice. Thank you so much!  i can continue my little
program again. :)

-- 
William


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2006-03-10 19:41 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-03-01  5:01 recv! and thread William Xu
2006-03-03 23:44 ` Kevin Ryde
2006-03-04  2:11   ` William Xu
2006-03-07 20:56     ` Kevin Ryde
2006-03-10 19:41       ` William Xu

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).