free allocated stack by execution thread 72/4872/1
Antoine ELIAS [Wed, 7 Sep 2011 14:25:13 +0000 (16:25 +0200)]
Change-Id: I464f6dd784335d0b9cdfa3965a4f0edff50b1fa9

scilab/modules/core/src/cpp/runner.cpp
scilab/modules/threads/src/cpp/Thread_Wrapper.cpp

index f596622..f8fc4c0 100644 (file)
@@ -97,6 +97,12 @@ void Runner::execAndWait(ast::Exp* _theProgram, ast::ExecVisitor *_visitor)
         ConfigVariable::addThread(new ThreadId(threadId, threadKey));
         //free locker to release thread && wait and of thread execution
         LockPrompt();
+
+        types::ThreadId* pExecThread = ConfigVariable::getThread(threadKey);
+        if(pExecThread == NULL)
+        {//call ptrhad_join to clean stack allocation
+            __WaitThreadDie(threadId);
+        }
     }
     catch(ScilabException se)
     {
index 882f1f0..96735cd 100644 (file)
@@ -133,18 +133,19 @@ void __CreateThreadWithParams(__threadId *threadId, __threadKey *threadKey, void
     pthread_attr_t threadAttr;
 #ifdef __APPLE__
     size_t size = 128 * 1024 * 1024;
-    void *stackbase = (void *) malloc(size);
+    //void *stackbase = (void *) malloc(size);
     pthread_attr_init(&threadAttr);
 
     pthread_attr_setstacksize(&threadAttr, size);
-    pthread_attr_setstackaddr(&threadAttr, stackbase);
+    //pthread_attr_setstackaddr(&threadAttr, stackbase);
     pthread_create(threadId, &threadAttr, functionName, params);
 #else //Linux
     size_t size = 128 * 1024 * 1024;
-    void *stackbase = (void *) malloc(size);
+    //void *stackbase = (void *) malloc(size);
     pthread_attr_init(&threadAttr);
 
-    pthread_attr_setstack(&threadAttr, stackbase, size);
+    //pthread_attr_setstack(&threadAttr, stackbase, size);
+    pthread_attr_setstacksize(&threadAttr, size);
     pthread_create(threadId, &threadAttr, functionName, params);
 #endif
     *threadKey = *threadId;