Nmap Development mailing list archives
Re: Thread Parallelism for Sockets (Fix for infinite loops/deadlocks in NSE)
From: "Patrick Donnelly" <batrick.donnelly () gmail com>
Date: Thu, 24 Jul 2008 04:14:57 -0700
On Thu, Jul 24, 2008 at 3:58 AM, Patrick Donnelly <batrick.donnelly () gmail com> wrote:
Some technical details of the implementation: 1) The open sockets are paired with a per thread unique userdata (henceforth called 'proxies') in a weak keyed table. When all sockets have closed or been collected, the userdata is collected and a slot is freed in a fully weak table with thread proxy pairs (which contains the number of threads with open sockets). When the proxy is collected (and thus a slot freed), a thread waiting to open a socket is moved to running and given a lock.
Here is the commented documentation on this, which may clear up any confusion: <code> /* Some constants used for enforcing a limit on the number of open sockets * in use by threads. The maximum value between MAX_PARALLELISM and * o.maxparallelism is the max # of threads that can have connected sockets * (open). THREAD_PROXY, SOCKET_PROXY, and CONNECT_WAITING are tables in the * nsock C functions' environment, at LUA_ENVIRONINDEX, that hold sockets and * threads used to enforce this. THREAD_PROXY has <Thread, Userdata> pairs * that associate a thread to a proxy userdata. This table has weak keys and * values so threads and the proxy itself can be collected. SOCKET_PROXY * has <Socket, Userdata> pairs that associate a socket to a proxy userdata. * SOCKET_PROXY has weak keys (to allow the collection of sockets) and strong * values, so the proxies are not collected when an associated socket is open. * * All the sockets used by a thread have the same Proxy Userdata. When all * sockets in use by a thread are closed or collected, the entry in the * THREAD_PROXY table is cleared, freeing up a slot for another thread * to make connections. When a slot is freed, proxy_gc is called, via the * userdata's __gc metamethod, which will add a thread in WAITING to running. */ #define MAX_PARALLELISM 10 #define THREAD_PROXY 1 /* <Thread, Userdata> */ #define SOCKET_PROXY 2 /* <Socket, Userdata> */ #define CONNECT_WAITING 3 /* Threads waiting to lock */ #define PROXY_META 4 /* Proxy userdata's metatable */ </code> Cheers, -- -Patrick Donnelly "One of the lessons of history is that nothing is often a good thing to do and always a clever thing to say." -Will Durant _______________________________________________ Sent through the nmap-dev mailing list http://cgi.insecure.org/mailman/listinfo/nmap-dev Archived at http://SecLists.Org
Current thread:
- Thread Parallelism for Sockets (Fix for infinite loops/deadlocks in NSE) Patrick Donnelly (Jul 24)
- Re: Thread Parallelism for Sockets (Fix for infinite loops/deadlocks in NSE) Patrick Donnelly (Jul 24)