[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Thread-safe initialization in a C extension

Wincent Colaiuta

7/4/2007 9:30:00 AM

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;
}