- PerlInterpreter *current_interp = PERL_GET_CONTEXT;
-
- perl_destruct(current_interp);
- perl_free(current_interp);
- PERL_SYS_TERM();
+ nmem_mutex_enter(simpleserver_mutex);
+ if (1)
+ {
+ PerlInterpreter *current_interp = PERL_GET_CONTEXT;
+
+ /* If current Perl Interp is different from root interp, then
+ * we're in threaded mode and we must destroy..
+ */
+ if (current_interp != root_perl_context) {
+ PL_perl_destruct_level = 2;
+ PERL_SET_CONTEXT(root_perl_context);
+ perl_destruct(current_interp);
+ perl_free(current_interp);
+ }
+ }
+ nmem_mutex_leave(simpleserver_mutex);