lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hello.

First of all, I appriciate all guys of Lua team. Interesting language.

I have a bit trouble with lua thread. I made a small sample code of 
just getting some web pages with luathread and luasocket. And it does
not work. Give me any help.

I guess there would be three possible cause.

a, My complie/install of luathread/luasocket is wrong.
   If so, tell me something from ldd output.
b. luasocket does not work under multi threading.
c. just my sample code is wrong.

Note: Two samples ( Parent-child and Producer-consumer from Diego's site)
      works well.


               --- Okajima, Jun. Tokyo, Japan.


----------------------------
okajima@Debian:~$ lua.thread http.sample.lua
start   2

( this must be like

  ----
   start 2
   start 3
   start 1
   start 4
   http://www.yahoo.co.jp/index.html 1 48712
   .....
   end
  ----
  , but lua terminated just after starting thread 2.
)
----------------------------
okajima@Debian:~$ cat http.sample.lua
function get(str, n)
    local http = require("socket.http")
    local out,len
    print("start", n)
    out = http.request(str)
    len = string.len(out)
    print(str, n, len)
end

thread.newthread(get,{"http://www.yahoo.co.jp/index.html";, 1})
thread.newthread(get,{"http://www.yahoo.com/index.html";, 2})
thread.newthread(get,{"http://www.google.co.jp/index.html";, 3})
thread.newthread(get,{"http://www.google.com/index.html";, 4})

os.execute("sleep 10")
print("end")
---------------------------
okajima@Debian:~$ ls -la /home/okajima/bin/lua.thread
-rwxr-xr-x  1 okajima okajima 171609 Aug 15 22:03 /home/okajima/bin/lua.thread
okajima@Debian:~$ ldd /home/okajima/bin/lua.thread
        libm.so.6 => /lib/tls/libm.so.6 (0xb7fc4000)
        libpthread.so.0 => /lib/tls/libpthread.so.0 (0xb7fb4000)
        libreadline.so.5 => /lib/libreadline.so.5 (0xb7f87000)
        libhistory.so.5 => /lib/libhistory.so.5 (0xb7f80000)
        libncurses.so.5 => /lib/libncurses.so.5 (0xb7f3e000)
        libdl.so.2 => /lib/tls/libdl.so.2 (0xb7f3b000)
        libc.so.6 => /lib/tls/libc.so.6 (0xb7e06000)
        /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0xb7fea000)
okajima@Debian:~$ find /usr/local/share/lua50/
/usr/local/share/lua50/
/usr/local/share/lua50/compat-5.1.lua
/usr/local/share/lua50/lmime.so
/usr/local/share/lua50/lsocket.so
/usr/local/share/lua50/ltn12.lua
/usr/local/share/lua50/mime.lua
/usr/local/share/lua50/socket
/usr/local/share/lua50/socket/ftp.lua
/usr/local/share/lua50/socket/http.lua
/usr/local/share/lua50/socket/smtp.lua
/usr/local/share/lua50/socket/tp.lua
/usr/local/share/lua50/socket/url.lua
/usr/local/share/lua50/socket.lua
/usr/local/share/lua50/thread
/usr/local/share/lua50/thread/queue.lua
okajima@Debian:~$ set | grep LUA
LUA_CPATH='/usr/local/share/lua50/?.so'
LUA_INIT=@/usr/local/share/lua50/compat-5.1.lua
LUA_PATH='/usr/local/share/lua50/?.lua'