Merge: PNaCl: Added 'create_thread' function in the pnacl lib.
authorJean Privat <jean@pryen.org>
Thu, 26 Jun 2014 17:16:00 +0000 (13:16 -0400)
committerJean Privat <jean@pryen.org>
Thu, 26 Jun 2014 17:16:00 +0000 (13:16 -0400)
Added 'create_thread' function to enable thread creation after a exit.

Pull-Request: #519
Reviewed-by: Lucas Bajolet <r4pass@hotmail.com>
Reviewed-by: Alexandre Terrasa <alexandre@moz-code.org>
Reviewed-by: Alexis Laferrière <alexis.laf@xymus.net>
Reviewed-by: Jean Privat <jean@pryen.org>

lib/pnacl.nit

index fde40f3..42a6b8c 100644 (file)
@@ -725,7 +725,21 @@ class PnaclApp
 end
 
 redef interface Object
-       # Calls 'pthread_exit on current thread
+       # Creates a new thread for Nit.
+       #
+       # This function launches the Nit main on a new thread.
+       # Its purpose is to allow Nit to be still operational after an exit when needed,
+       # because reloading the page may not be an option.
+       #
+       # Should only be used within the 'exit' before stopping the current thread
+       # when the Nit execution causes a crash.
+       #
+       # REQUIRE: g_nit_thread and WrapperNitMain are set.
+       fun create_thread `{
+               pthread_create(&g_nit_thread, NULL, &WrapperNitMain, NULL);
+       `}
+
+       # Calls 'pthread_exit on current thread.
         fun exit_thread(exit_value: Int) `{
                pthread_exit((void*) exit_value);
        `}