diff options
author | Dick Porter <dick@acm.org> | 2003-01-23 20:46:26 +0300 |
---|---|---|
committer | Dick Porter <dick@acm.org> | 2003-01-23 20:46:26 +0300 |
commit | 9b5c149aec6d102a015c353b28fee08a1bae4009 (patch) | |
tree | ab1012cf0886c0568830d959c05d7f963b1e280b /samples | |
parent | 7f33ba9dd9a59ace37074d17387e9524c074c930 (diff) |
Run all managed code in a subthread. Re-enable GC threaded finalisation.
Fixes bugs 34263 and 31333.
(All tests still behave the same way - 4 fails)
2003-01-23 Dick Porter <dick@ximian.com>
* threads.c (start_wrapper): Create a Thread object if needed, so
the Main() thread can do the class initialisation in a subthread
that has been set up to allow managed code execution.
Pass the thread ID instead of the MonoThread pointer to the thread
start and attach callbacks. This change is required, because the
jit thread start callback must be called _before_ the Thread
object can be created.
(mono_thread_init): Removed much object creation code that is no
longer needed. No managed code is called from here now.
* object.c (mono_runtime_exec_managed_code): Create a subthread
for Main, and call back to the runtime to use it.
Set the exit code when Main exits.
* gc.c: Make sure domain finalisation happens in a subthread.
Re-enable threaded GC, fixing bug 31333 (again).
* environment.c: System.Environment internall calls (so far just
ExitCode is here, the others are still in icall.c)
* appdomain.c (mono_runtime_cleanup): All threads running managed
code should have finished before mono_runtime_cleanup() is
reached, so no need to clean up threads.
2003-01-23 Dick Porter <dick@ximian.com>
* mono.c: Use mono_runtime_exec_managed_code() to run all managed
code in a subthread.
* jit.c: Changed thread start and attach callbacks to pass the
thread ID, not the MonoThread pointer. Arrange that managed code
execution will fail an assertion in the main thread, just to be
sure.
2003-01-23 Dick Porter <dick@ximian.com>
* interp.c: Use mono_runtime_exec_managed_code() to run all
managed code in a subthread.
svn path=/trunk/mono/; revision=10838
Diffstat (limited to 'samples')
-rw-r--r-- | samples/embed/teste.c | 51 |
1 files changed, 41 insertions, 10 deletions
diff --git a/samples/embed/teste.c b/samples/embed/teste.c index ee7b84227d7..eb7131508c6 100644 --- a/samples/embed/teste.c +++ b/samples/embed/teste.c @@ -1,4 +1,5 @@ #include <mono/jit/jit.h> +#include <mono/metadata/environment.h> /* * Very simple mono embedding example. @@ -14,13 +15,40 @@ gimme () { return mono_string_new (mono_domain_get (), "All your monos are belong to us!"); } +typedef struct +{ + MonoDomain *domain; + const char *file; + int argc; + char **argv; +} MainThreadArgs; + +static void main_thread_handler (gpointer user_data) +{ + MainThreadArgs *main_args=(MainThreadArgs *)user_data; + MonoAssembly *assembly; + + assembly = mono_domain_assembly_open (main_args->domain, + main_args->file); + if (!assembly) + exit (2); + /* + * mono_jit_exec() will run the Main() method in the assembly. + * The return value needs to be looked up from + * System.Environment.ExitCode. + */ + mono_jit_exec (main_args->domain, assembly, main_args->argc, + main_args->argv); +} + + int main(int argc, char* argv[]) { MonoDomain *domain; - MonoAssembly *assembly; const char *file; int retval; - + MainThreadArgs main_args; + if (argc < 2){ fprintf (stderr, "Please provide an assembly to load"); return 1; @@ -36,14 +64,17 @@ main(int argc, char* argv[]) { * can call us back. */ mono_add_internal_call ("Mono::gimme", gimme); - assembly = mono_domain_assembly_open (domain, file); - if (!assembly) - return 2; - /* - * mono_jit_exec() will run the Main() method in the assembly - * and return the value. - */ - retval = mono_jit_exec (domain, assembly, argc - 1, argv + 1); + + main_args.domain=domain; + main_args.file=file; + main_args.argc=argc-1; + main_args.argv=argv+1; + + mono_runtime_exec_managed_code (domain, main_thread_handler, + &main_args); + + retval=mono_environment_exitcode_get (); + mono_jit_cleanup (domain); return retval; } |