multithreading - Ruby GIL of MRI 1.9 -
in understanding, here's how mri 1.9 gil works:
- interpreter spawns new thread calling corresponding underlying c function , ask acquire "gil".
- if "gil" free, happy. if not, new thread wait , invoke separate timer thread set "timeslice"
- when current executing thread hit boundaries such return or checking backward branches, interpreter checks timer decide if context switch should happen.
however, pointed article, can guarantee atomicity pure c implementing. being said, if parts of our thread contains ruby code, still in danger of race condition.
my question if thread needs acquire gil before executing, why c implementation methods guarantee atomicity?
thank in advance!
the gvl guarantees 1 thread can execute ruby code @ same time. of course different ruby threads can execute ruby code @ different times.
besides, majority of ruby implementations doesn't have gvl anyway.
Comments
Post a Comment