On Thu, Jun 30, 2016 at 12:14:00PM -0600, Robert Smiley wrote:
> Hi guys. I'm not very familiar with the low level details, but the
> documentation for srfi-18 found here.
> 
> https://wiki.call-cc.org/man/4/Unit%20srfi-18
> 
> Contains this quote
> 
> "Blocking I/O will block all threads, except for some socket operations
> (see the section about the tcp unit). An exception is the read-eval-print
> loop on UNIX platforms: waiting for input will not block other threads,
> provided the current input port reads input from a console."

I guess this isn't entirely correct, given your hanging program.

> When I try running the following code:

[code]

> No matter how long I wait before hitting enter, result printed is always 0.
> Although I'm fairly inexperienced, I believe this means that the thread is
> not running, due to chicken blocking on the call to read-line as it waits
> for my input. The thread is never run, and never increments var.

That's right.  A simple way around this is to wrap the port in Parley,
which will make the port nonblocking:

(use srfi-18 parley)

(current-input-port (make-parley-port old)))

(define var 0)
(define thread (make-thread (lambda () (let loop ()
                                           (set! var (add1 var))
                                           (loop)))))
(thread-start! thread)
(read-line)
(print var)

But yeah, the current situation is still a big mess.  Sorry :(

Cheers,
Peter

Attachment: signature.asc
Description: Digital signature

_______________________________________________
Chicken-users mailing list
[email protected]
https://lists.nongnu.org/mailman/listinfo/chicken-users

Reply via email to