Calling method using main thread from secondary thread

I have called a method using a secondary thread. From inside the method i need to call a method from main thread.

here is the structure

void main_thread_method()
{

} 

void secondary_thread_method()
{

//do something here

  call main_thread_method() here using main thread

}

pthread thread1;

pthread_create (&thread1, NULL, (void *) &secondary_thread_method, NULL);

pthread_join(thread1);

Answers


If your main thread is running a message pump you can post a message somehow to execute a function when your message is received.

Otherwise have a simple queue ( appropriate locking of course ). Add enough data into the queue so that main_thread_method can be called. (args etc). Periodically poll the simple queue for new messages in the main thread and process them.


Need Your Help

Filter called sveral times by Tomcat container

java servlets servlet-filters

I would like some help in understanding a particular behaviour of java Filters: I wrote a simple Filter which gets all user requests and, if a non-logged user requires a restricted resource, the fi...

Does Ruby Sequel have an equivalent for the SQL “coalesce” function?

sequel coalesce

In SQL in order to avoid getting a NULL value, I can use the "coalesce" function to substitute it like so:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.