Thread-safe initialization in a C extension

  • Thread starter Wincent Colaiuta
  • Start date
W

Wincent Colaiuta

I'm working on a Ruby extension written in C and I would like to know
what implications Ruby 1.8's "green" threading model has for the once-
only initialization of file-scoped static variables.

The following is my code with no explicit attempts at thread-safety.
Do I need them under "green" threading?

Cheers,
Wincent

static VALUE rb_Iconv = 0;

VALUE _setup_iconv()
{
// no attempt at thread safety here (TODO: add it?)
if (rb_Iconv == 0)
{
rb_require("iconv");
rb_Iconv = rb_path2class("Iconv");
if (NIL_P(rb_Iconv))
rb_raise(rb_eLoadError, "failed to load Iconv class");
else
return Qtrue;
}
return Qfalse;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top