At Wed, 7 Oct 2015 08:40:12 +0200, Berthold Bäuml wrote:
> does call-as-atomic block garbage collection?

No.

> I want to call a C function from 
> Racket which  takes a pointer to a struct as an argument. The struct consists 
> of a mixture of atomic and pointer fields and  one of the pointers should 
> directly point to a flvector (by using flvector->cpointer) for performance 
> reasons (zero copy). 
> 
> Due to the mixed fields neither atomic nor non-atomic malloc works 
> (correct?). 
> Is using call-as-atomic the right way to go to avoid garbage collection 
> between setting the pointer field in the struct and calling the C function?

No.

I think you'd like a way to tell the GC how to find the pointers in a
block of allocated memory, and I think we'll get there before too long.

For now, here's my best idea:

 * Once per place, allocate a static block of memory with `(malloc
   'atomic-interior ...)`, and register it in scheme_get_place_table()
   using some key. A sufficiently obscure symbol should work as a key,
   in this case.

   The step of registering in scheme_get_place_table() lets you find an
   already-allocated block, and it also ensures that the block will
   remain live as long as the place does.

 * Use scheme_register_static() to register the pointer positions
   within the per-place block of memory. (Do that only once for the
   allocated block.)

   Note that it's important for the block to live as long as the place
   does, since there's no way to revoke a static registration.

 * Fill the block of memory with values to pass to the function just
   before calling the function. To make that process thread-safe at the
   level of Racket threads, use atomic mode to fill the block of memory
   and call the function. (Having a per-place block of memory makes it
   thread-safe at the level of OS threads.)

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to