how to make a function thread safe?



Hi,

is a function thread save when all inside code is wrapped into a static
mutex?

What is with this function: Could a second thread influence the first
thread while it is looping (because of the pointer argument)?


void f(gint* my_gint){

  static GStaticMutex my_mutex = G_STATIC_MUTEX_INIT;

  g_static_mutex_lock(&my_mutex);

  while(TRUE)
  {
    
    g_printf("value: %d\n", *my_gint);

    /* ... */

  }

  g_static_mutex_unlock(&my_mutex);
}






[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]