use warnings; use Inline C => Config => NAME => 'expt', BOOT => " { MY_CXT_INIT; MY_CXT.count = 5; } ", BUILD_NOISY => 1, ; use Inline C => <<'EOC'; #define MY_CXT_KEY "expt::_guts" XS_VERSION typedef struct { int count; } my_cxt_t; START_MY_CXT void set_x(int z) { dMY_CXT; MY_CXT.count = z; } void get_x(char * id) { dMY_CXT; printf("%s %d\n", id, MY_CXT.count); } void CLONE(SV * x, ...) { MY_CXT_CLONE; } EOC get_x('1st call:'); if($pid = fork()) { waitpid($pid,0); } else { set_x(10); get_x('2nd call:'); exit(0); } get_x('3rd call:');