From 9857411032977415de5e39de6ee39d838eb78773 Mon Sep 17 00:00:00 2001 From: david Date: Sat, 8 Jan 2011 07:20:40 +0000 Subject: [PATCH] Pre-prime the first list of CONCURRENCY_LIMIT threads, and bail out early if there are none to be run. This avoids printing ScanProgressMeter messages. --- nse_main.lua | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/nse_main.lua b/nse_main.lua index b9f138e66..be0185354 100644 --- a/nse_main.lua +++ b/nse_main.lua @@ -634,7 +634,6 @@ local function run (threads_iter, scantype) local current; -- The currently running Thread. local total = 0; -- Number of threads, for record keeping. local timeouts = {}; -- A list to save and to track scripts timeout. - local progress = cnse.scan_progress_meter(NAME); local num_threads = 0; -- Number of script instances currently running. -- Map of yielded threads to the base Thread @@ -708,6 +707,22 @@ local function run (threads_iter, scantype) return current.co; end); + while threads_iter and num_threads < CONCURRENCY_LIMIT do + local thread = threads_iter() + if not thread then + threads_iter = nil; + break; + end + all[thread.co], running[thread.co], total = thread, thread, total+1; + num_threads = num_threads + 1; + thread:start(timeouts); + end + if num_threads == 0 then + return + end + + local progress = cnse.scan_progress_meter(NAME); + -- Loop while any thread is running or waiting. while next(running) or next(waiting) or threads_iter do -- Start as many new threads as possible.