[racket] How to invoke a blocking foreign function without blocking whole racket?

From: Haiwei Zhou (highfly22 at gmail.com)
Date: Wed Jan 30 04:40:33 EST 2013

Finally, I figured out the callback from this letter:
http://lists.racket-lang.org/users/archive/2010-July/040409.html . I wish I
red this letter early.

After realized that the foreign function blocks the caller thread, I used
dynamic-place to create worker thread. The code is here :
https://github.com/highfly22/alert/blob/master/inotify.rkt

Racket is amazing simple after you know the bloody details.

Haiwei


On 30 January 2013 14:23, Haiwei Zhou <highfly22 at gmail.com> wrote:

> Hi,
>
>  I try to wrap inotify API. After adding a watcher, I try to read events
> from file descriptor. But the racket thread is blocking until the read
> operation is done. Here is the definition of read.
>
> (define _read (get-ffi-obj "read" libc (_fun #:async-apply (lambda (f) (f))
>                                              #:save-errno 'posix
>                                             _fd_t
>                                             (output : (_bytes o size))
>                                             (size : _uint32)
>                                             -> (r : _int32)
>                                             -> (values r saved-errno
> output))))
>
> I am confused by the term callback. Is the callback called in the racket
> thread or another OS thread?
>
> Thanks,
> Haiwei
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20130130/a5783097/attachment.html>

Posted on the users mailing list.