openresty中每个request创建一个coroutine, coroutine如果没有做I/O操作和sleep是不是会一直占用lua vm,直到这个请求结束?
openresty的coroutine调度机制是不是遇到I/O和sleep就让出CPU,其他情况不会让出CPU?
local _M = {}
local ffi = require("ffi")
ffi.cdef[[
typedef long time_t;
typedef struct timeval {
time_t tv_sec;
time_t tv_usec;
} timeval;
int gettimeofday(struct timeval* t, void* tzp);
]]
local _M.gettimeofday_struct = ffi.new("timeval")
local function gettimeofday()
ffi.C.gettimeofday(_M.gettimeofday_struct, nil)
return tonumber(_M.gettimeofday_struct.tv_sec) * 1000000 + tonumber(_M.gettimeofday_struct.tv_usec)
end
我这个模块有一个模块变量gettimeofday_struct, 在openresty中多个request(coroutine) 会访问这个变量,请问会不会有race condition的问题?