Ehsan Akhgari wrote:
When you pass a pointer to a function to your thread, and then let the
thread call that function, that function is called within the context of
the calling thread.  To execute a function in the contect of another
thread, you need to somehow alert the other thread to execute that
function.  The simplest solution to this problem on Win32 is posting a
user-defined message to the other thread.  But I don't have any idea how
portable this is to other platforms, as I have never used threads in
anywhere except Win32.

Ok thank you. Indeed I learned the hard way that that calling a function (even through a pointer) from a thread is executed in that thread's context (although I couldn't word it so nice ;) ), and I should have known that it works that way if I had thought it over :) In Gtk there is a way to let the main loop handle a function in the context of the main program (g_idle_add() for the completeness of the archive) but I haven't found a portable solution yet.
The problem with the user-defined message is ofcourse that it needs a HWND, which is very specific for windows. I have solved other (win32) threading problems this way, and it worked fine - but cross-platform threading seems to be a hard problem.
Anyway, I'll go ask around on a couple of pthreads mailing lists about it. Thanks everybody for your input.


cheers,

roel






Reply via email to