6cc5c33 threadpool: Switch to detached threads

Authored and Committed by Jiri Denemark 8 years ago
    threadpool: Switch to detached threads
    
    Using joinable threads does not help anything, but it can lead to memory
    leaks.
    
    When a worker thread exits, it decreases nWorkers or nPrioWorkers and
    once both nWorkers and nPrioWorkers are zero (i.e., the last worker is
    gone), quit_cond is signaled. When freeing the pool we first tell all
    threads to die and then we are waiting for both nWorkers and
    nPrioWorkers to become zero. At this point we already know all threads
    are gone. So the only reason for calling virThreadJoin of all workers is
    to free the memory allocated for joinable threads. If we avoid
    allocating this memory, we don't need to take care of freeing it.
    
    Moreover, any memory associated with a worker thread which died before
    we asked it to die (e.g., because virCondWait failed in the thread)
    would be lost anyway since virThreadPoolFree calls virThreadJoin only
    for threads which were running at the time virThreadPoolFree was called.
    
    Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
    
        
file modified
+3 -14