Closed mikkoau closed 5 years ago
Did you join the thread or is the join missing somewhere in the implementation?
libdash library uses pthreads internally through MultiThreading abstraction (and thread handle is private in AbstractChunk class). So threads are not revealed through public interface's include files.
Internal implementation (~AbstractChunk) calls DestroyThreadPortable() but that only releases thread handle variable. There's no pthread_join() call in MultiThreading.cpp. Detaching is better approach imho since thread's return value is not needed.
We're using libdash's default segment download implementation on Linux to download 10+ adaptationsets simultaneously with 1 second segment length. The default implementation creates a new pthread instance for each segment but doesn't release thread resources (and stack 1-2MB/each?) when the download finishes. This resource leak killed our application in 3-5 minutes when testing with a machine with 2GB of RAM.
This fix creates pthreads as detached so they'll free resources automatically when thread function finishes.
More info: http://man7.org/linux/man-pages/man3/pthread_detach.3.html " Either pthread_join(3) or pthread_detach() should be called for each thread that an application creates, so that system resources for the thread can be released. "