Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?

rb_thread_call_without_gvl を使う

例えば普通に書くと

nvrtcResult status = nvrtcCreateProgram(&_prog, _src, _name, _numHeaders, _headers, _includeNames);

となる C 関数の呼び出しを、GVLを外して呼び出すには、

struct nvrtcCreateProgramParam {
    nvrtcProgram *prog;
    const char* src;
    const char *name;
    int numHeaders;
    const char** headers;
    const char** includeNames;
};

static void*
nvrtcCreateProgram_without_gvl_cb(void *param)
{
    struct nvrtcCreateProgramParam *p = param;
    nvrtcResult status;
    status = nvrtcCreateProgram(p->prog, p->src, p->name, p->numHeaders, p->headers, p->includeNames);
    return (void *)status;
}

struct nvrtcCreateProgramParam param = {&_prog, _src, _name, _numHeaders, _headers, _includeNames};
status = (nvrtcResult)rb_thread_call_without_gvl(nvrtcCreateProgram_without_gvl_cb, &param, NULL, NULL);

こんなかんじになる。struct と callback 関数を作る必要があるので非常にめんどい。

@sonots

This comment has been minimized.

Copy link
Owner Author

@sonots sonots commented Apr 19, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.