bugfix: reclaim thread stack explicitly by using detached threads

Otherwise the VmData size will keep increasing in multi-threads mode.
Although the increasing VmData size doesn't mean there is enormous
memory leak, it does show that the thread stack is not handled properly
when threads exit.
This commit is contained in:
chrox
2012-11-22 01:37:41 +08:00
parent b8131a1906
commit 060eeec1c1
2 changed files with 8 additions and 2 deletions

5
djvu.c
View File

@@ -531,7 +531,10 @@ static int reflowPage(lua_State *L) {
kctx->src = src;
if (kctx->precache) {
pthread_t rf_thread;
pthread_create(&rf_thread, NULL, k2pdfopt_reflow_bmp, (void*) kctx);
pthread_attr_t attr;
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
pthread_create(&rf_thread, &attr, k2pdfopt_reflow_bmp, (void*) kctx);
} else {
k2pdfopt_reflow_bmp(kctx);
}

5
pdf.c
View File

@@ -615,7 +615,10 @@ static int reflowPage(lua_State *L) {
kctx->src = src;
if (kctx->precache) {
pthread_t rf_thread;
pthread_create( &rf_thread, NULL, k2pdfopt_reflow_bmp, (void*) kctx);
pthread_attr_t attr;
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
pthread_create( &rf_thread, &attr, k2pdfopt_reflow_bmp, (void*) kctx);
} else {
k2pdfopt_reflow_bmp(kctx);
}