modu_UnloadAllModules

[<<<] [>>>]

@c Unload all loaded modules

This function unloads all modules. This is called via the command finalizer mechanizm. If ever any module was loaded via a "declare sub" statement the command execution sets the command finalizer function pointer to point to this function.

int modu_UnloadAllModules(pExecuteObject pEo
  )@{

In a multi-threaded environment this function calls the keeper function of the module and in case the keeper returns 1 the module is kept in memory, though the module finalizer function is called. This lets multi-thread external modules to keep themselfs in memory even those times when there is not any interpreter thread using the very module running.

In that case the module is put on the module list of the process SB object. That list is used to shut down the modules when the whole process is shut down.

If there is no process SB object (pEo->pEPo is NULL) then the variation is a single process single thread implementation of ScriptBasic. In this case this function first calls the module finalizer function that is usally called in multi-threaded environment every time an interpreter thread is about to finish and after this the module shutdown function is called, which is called in a multi-thread environment when the whole process is to be shut down. After that the module is unloaded even if the keeper function said that the module wants to stay in memory.

Don't worry about this: it is not abuse. The keeper function saying 1 means that the module has to stay in memory after the actual interpreter thread has finished until the process finishes. However in this very case the process also terminates.

Note: A one-process one-thread implementation may also behave like a multi thread implementation allocating a separate process SB object and a program object to run. Then it should inherit the support table and the execution object of the process SB object to the runnable program object. After running finish the runned program object and call the shutdown process for the process SB object. But that is tricky for a single thread implementation.


[<<<] [>>>]