Yes. I realized that too late. I already sent a patch to Jürg on
Saturday. But as you seem to need it now I'll also post it here on the
mailing list. 

This patch swaps the generation of the g_thread_init and the
g_mem_set_vtable.
This is needed for multithreaded programs.
Regards Jörn


Am Montag, den 11.01.2010, 12:02 +0800 schrieb xiaohu:
> I just try it, the generated code has little problem. as below:
> 
> int main (int argc, char ** argv) {
>         g_thread_init (NULL);
>         g_mem_set_vtable (glib_mem_profiler_table);
>         g_type_init (); 
>         return eshare_main_main (argv, argc);
> }
> 
> g_mem_set_vtable (...) should be called before g_thread_init().
> 
> thanks!
> 
> 在 2010-01-09六的 17:06 +0100,JM写道: 
> > I wrote a patch for this. This patch has just been added to vala git.
> > Now, you can set the default table via commandline switch.
> > Regards 
> > Jörn
> > 
> > Am Sonntag, den 13.12.2009, 12:39 +0000 schrieb xiaohu:
> > > vala code:
> > > 
> > > int main ()
> > > {
> > >   mem_set_vtable (mem_profiler_table);
> > >   return 0;
> > > }
> > > 
> > > will generate:
> > > 
> > > #include <glib.h>
> > > #include <glib-object.h>
> > > 
> > > gint _main (void);
> > > 
> > > gint _main (void) {
> > >         gint result;
> > >         g_mem_set_vtable (glib_mem_profiler_table);
> > >         result = 0;
> > >         return result;
> > > }
> > > 
> > > int main (int argc, char ** argv) {
> > >         g_type_init (); 
> > >         return _main (); 
> > > }
> > > 
> > > there has a problem, g_mem_set_vtable () must be called before using any
> > > other GLib functions.
> > > 
> > > How to call mem_set_vtable ?
> > > _______________________________________________
> > > Vala-list mailing list
> > > [email protected]
> > > http://mail.gnome.org/mailman/listinfo/vala-list
> > 
> 

diff --git a/codegen/valaccodemethodmodule.vala b/codegen/valaccodemethodmodule.vala
index b2c28ef..3a4fcf6 100644
--- a/codegen/valaccodemethodmodule.vala
+++ b/codegen/valaccodemethodmodule.vala
@@ -752,13 +752,6 @@ internal class Vala.CCodeMethodModule : CCodeStructModule {
 			var main_block = new CCodeBlock ();
 
 			if (context.profile == Profile.GOBJECT) {
-				if (context.thread) {
-					var thread_init_call = new CCodeFunctionCall (new CCodeIdentifier ("g_thread_init"));
-					thread_init_call.line = cmain.line;
-					thread_init_call.add_argument (new CCodeConstant ("NULL"));
-					main_block.add_statement (new CCodeExpressionStatement (thread_init_call));
-				}
-
 				if (context.mem_profiler) {
 					var mem_profiler_init_call = new CCodeFunctionCall (new CCodeIdentifier ("g_mem_set_vtable"));
 					mem_profiler_init_call.line = cmain.line;
@@ -766,6 +759,13 @@ internal class Vala.CCodeMethodModule : CCodeStructModule {
 					main_block.add_statement (new CCodeExpressionStatement (mem_profiler_init_call));
 				}
 
+				if (context.thread) {
+					var thread_init_call = new CCodeFunctionCall (new CCodeIdentifier ("g_thread_init"));
+					thread_init_call.line = cmain.line;
+					thread_init_call.add_argument (new CCodeConstant ("NULL"));
+					main_block.add_statement (new CCodeExpressionStatement (thread_init_call));
+				}
+
 				var type_init_call = new CCodeExpressionStatement (new CCodeFunctionCall (new CCodeIdentifier ("g_type_init")));
 				type_init_call.line = cmain.line;
 				main_block.add_statement (type_init_call);
_______________________________________________
Vala-list mailing list
[email protected]
http://mail.gnome.org/mailman/listinfo/vala-list

Reply via email to