> I have a very basic question about threading. I would like to > run a part > of my program (a download) in a separate thread and then call a > funciton in the the main program again and have that main > program update > the UI. Now I thought I'd be clever and pass the address of a > function > in the main program into the thread and have the thread call that > function when it's finished but I found out that that call will just > stay in the current thread. I'd like to do this in a portable > (win32/posix threads) way so I prefer a solution that doesn't > depend on > win32. Of course I already thought about hacks like a global boolean > that will be checked in a busy loop with a ::Sleep() by the main > program, but that's not the sort of solution I'm after. So if anyone > could tell me how to solve this or point me to a document > that describes > this sort of basic threading synchronization issues I'd be > grateful. I > figured this sort of question would be appropriate for a > 'beginthread.com' list ;)
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.
