Re: [Vala] Threads and async (was: Threads and closures problem)
- From: Michael 'Mickey' Lauer <mickey vanille-media de>
- To: Vala-list <Vala-list gnome org>
- Subject: Re: [Vala] Threads and async (was: Threads and closures problem)
- Date: Thu, 14 Jan 2010 01:57:27 +0100
Ok, I just tried the following program:
=================================================
void* thread_func_1()
{
var loop = new MainLoop();
async_func_1();
loop.run();
return null;
}
void* thread_func_2()
{
var loop = new MainLoop();
async_func_2();
loop.run();
return null;
}
async void async_func_1()
{
message( "thread %d", (int)Linux.gettid() );
Thread.usleep( 1000 * 1000 );
yield async_func_1();
}
async void async_func_2()
{
message( "thread %d", (int)Linux.gettid() );
Thread.usleep( 1000 * 1000 );
yield async_func_2();
}
void main()
{
Thread.create( thread_func_1, false );
Thread.create( thread_func_2, false );
while ( true )
{
message( "main thread %d", (int)Linux.gettid() );
Thread.usleep( 1000 * 1000 * 2 );
}
}
=================================================
And to my amazement, the output looked like that:
** Message: thread.vala:37: main thread 12070
** Message: thread.vala:19: thread 12071
** Message: thread.vala:26: thread 12072
** Message: thread.vala:19: thread 12071
** Message: thread.vala:26: thread 12072
** Message: thread.vala:37: main thread 12070
** Message: thread.vala:19: thread 12071
** Message: thread.vala:26: thread 12072
** Message: thread.vala:19: thread 12071
** Message: thread.vala:26: thread 12072
Reading a bit further into the glib docs, it clearly states that the
"default" context is thread specific.
Very good,
:M:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]