Hooking into the VM's shutdown process

I’ve got a native extension that needs to run in a thread separate
from the Ruby VM. But the problem is that I can’t find a way to signal
that process that it needs to stop running when the Ruby VM shuts
down. IOW, I need a way to hook into the Ruby VM’s shutdown process so
I can notify this thread to exit.

Any clue on how to do this?

Am 09.05.2012 17:44, schrieb Darryl L. Pierce:

I’ve got a native extension that needs to run in a thread separate
from the Ruby VM. But the problem is that I can’t find a way to signal
that process that it needs to stop running when the Ruby VM shuts
down. IOW, I need a way to hook into the Ruby VM’s shutdown process so
I can notify this thread to exit.

Any clue on how to do this?

Probably you could write a C function to do the notification, then
bridge that C function over to Ruby, and from there call it inside an
#at_exit handler?

Vale,
Marvin

On Wed, May 9, 2012 at 11:51 AM, Quintus [email protected]
wrote:

Probably you could write a C function to do the notification, then
bridge that C function over to Ruby, and from there call it inside an
#at_exit handler?

Ah, thank you. Any examples of how to use that?

“Darryl L. Pierce” [email protected] wrote:

On Wed, May 9, 2012 at 11:51 AM, Quintus [email protected] wrote:

Probably you could write a C function to do the notification, then
bridge that C function over to Ruby, and from there call it inside an
#at_exit handler?

Ah, thank you. Any examples of how to use that?

If you don’t need the Ruby API, atexit(3).

Ruby 1.9.3+ also has ruby_vm_at_exit() (documented in NEWS-1.9.3, so
it’s likely to remain supported).

Otherwise, define a Ruby method and call it via at_exit {} in Ruby:

at_exit { MyModule.destroy }