aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/LuaSL/testLua/luaprocTest1.lua
blob: 3fe48115ef840fece29eef1c37c875ad82c57678 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
require "luaproc"

result, error_msg = luaproc.createworker()
if not result then print(error_msg) end
result, error_msg = luaproc.createworker()
if not result then print(error_msg) end
result, error_msg = luaproc.createworker()
if not result then print(error_msg) end
result, error_msg = luaproc.createworker()
if not result then print(error_msg) end

result, error_msg = luaproc.newproc( [=[

    local count = 0

-- Hmm, luajit 2 beta 9 crashes at about 8140, lua can go up to 50000 at least.
    for i = 1, 8000 do
	local channel = "channel" .. i
--	local proc = 'print(luaproc.receive("channel' .. i .. '") .. " " .. ' .. i ..')'
	local proc = 'luaproc.receive("' .. channel .. '")'

--	print(channel .. "\n" .. proc)
	result, error_msg = luaproc.newchannel(channel)
	if not result then print(error_msg) end
	result, error_msg = luaproc.newproc(proc)
	if not result then print(error_msg) else count = count + 1 end
    end

    print("Started " .. count .. " Lua threads")

    if 0 ~= count then
	for i = 1, count do
	    result, error_msg = luaproc.send("channel" .. i, 'luaproc is working fine! ' .. i)
	    if not result then print(error_msg .. " " .. i) end
	end
    end
]=] )
if not result then print(error_msg .. " for main proc") end

luaproc.exit()