Parcourir la source

support check if thread create succeed

pikastech il y a 2 ans
Parent
commit
0285c19abd

+ 5 - 0
package/_thread/_thread.c

@@ -94,4 +94,9 @@ void _thread_start_new_thread(PikaObj* self, Arg* function, Arg* args_) {
     info->thread = pika_platform_thread_init(
         "pika_thread", _thread_func, info, PIKA_THREAD_STACK_SIZE,
         PIKA_THREAD_PRIO, PIKA_THREAD_TICK);
+    if (NULL == info->thread) {
+        pikaFree(info, sizeof(pika_thread_info));
+        obj_setErrorCode(self, PIKA_RES_ERR_RUNTIME_ERROR);
+        obj_setSysOut(self, "thread create failed");
+    }
 }

+ 5 - 0
port/linux/package/pikascript/pikascript-lib/_thread/_thread.c

@@ -94,4 +94,9 @@ void _thread_start_new_thread(PikaObj* self, Arg* function, Arg* args_) {
     info->thread = pika_platform_thread_init(
         "pika_thread", _thread_func, info, PIKA_THREAD_STACK_SIZE,
         PIKA_THREAD_PRIO, PIKA_THREAD_TICK);
+    if (NULL == info->thread) {
+        pikaFree(info, sizeof(pika_thread_info));
+        obj_setErrorCode(self, PIKA_RES_ERR_RUNTIME_ERROR);
+        obj_setSysOut(self, "thread create failed");
+    }
 }