On Wed, Mar 16, 2016 at 5:03 PM, humphery <humph...@gmail.com> wrote:
> rt
>
> 示例:
>
> local globalVar ...
>
> location = /t {
> content_by_lua_block {
> local semaphore = require "ngx.semaphore"
> local sema = semaphore.new()
>
> local function handler()
> ngx.say("sub thread: waiting on sema...")
>
> local ok, err = sema:wait(1) -- wait for a second at most
> if not ok then
> ngx.say("sub thread: failed to wait on sema: ", err)
> else
> ngx.say(globalVar["var"])
> end
> end
>
> local co = ngx.thread.spawn(handler)
>
> globalVar["test"]={sema:sema}
> }
> }
>
> location = /o {
> content_by_lua_block {
> local sema = globalVar["test"]
> globalVar["var"]="1"
> sema:post(1)
> globalVar["var"]="2"
> sema:post(1)
> }
> }
对于 sem 的共享,应该使用
https://github.com/iresty/nginx-lua-module-zh-wiki#data-sharing-within-an-nginx-worker
类方法。谁先引用的,如果发现 sem 为空,先创建一下。
>
> 如连续调用/o返回值应是多少?
> /t 和 /o 先后顺序是怎样的?
>
> --
按照上面的连接用法,没有先后顺序一说,谁先谁后可以的(这个 API 我还没深入使用,说错了 @doujiang 批评指正)。
> --
YuanSheng Wang
---------------------------------------
My Github: https://github.com/membphis
OpenResty lover ^_^