in reply to CGI and Threads

Even if you detect the disconnection and you can shutdown the threads - which is very complex - and if you have database or file system actions within the thread's code it might leave junk there ( i.e. some records inserted but not all of them ).

I don't know what is your app doing but like suggested here I'd recommend Ajax, since it will give you flexibility in terms the maybe not all clients need all information so you can request partial information. Also it will give your page the sense of being fast because you render the page immediately and load results as they arrive without waiting the all threads to generate the payload and render the page

Another approach if the work the threads do is limited is to have a batch job that fetches the information and caches it in your side, so faster render times and no need for threads.