Пример #1
0
void dp_deep_evaluate_step(DpDeepInfo*hdeepinfo)
{
	GMainContext *gcontext = g_main_context_default();
	int individ_id;
	gboolean immediate_stop = FALSE;
	gboolean wait_finish = TRUE;
	DpPopulation*population = hdeepinfo->population;
	DpPopulation*trial = hdeepinfo->trial;
	GError *gerror = NULL;
	gulong microseconds = G_USEC_PER_SEC / 1000;
	if ( hdeepinfo->max_threads > 0 ) {
		for ( individ_id = population->slice_a; individ_id < population->slice_b; individ_id++ ) {
			g_thread_pool_push (hdeepinfo->gthreadpool, GINT_TO_POINTER(individ_id + 1), &gerror);
			if ( gerror != NULL ) {
				g_error("%s", gerror->message);
			}
		}
        while(g_thread_pool_unprocessed (hdeepinfo->gthreadpool) > 0) {
			g_main_context_iteration(gcontext, FALSE);
            g_usleep (microseconds);
        }
	} else {
		for ( individ_id = population->slice_a; individ_id < population->slice_b; individ_id++ ) {
			dp_deep_evaluate_func (GINT_TO_POINTER(individ_id + 1), (gpointer) hdeepinfo);
		}
	}
}
static void
test_thread_idle_time ()
{
  guint limit = 50;
  guint interval = 10000;
  gint i;

  idle_pool = g_thread_pool_new (test_thread_idle_time_entry_func, 
				 NULL, 
				 MAX_THREADS,
				 FALSE,
				 NULL);

  g_thread_pool_set_max_unused_threads (MAX_UNUSED_THREADS);  
  g_thread_pool_set_max_idle_time (interval); 

  g_assert (g_thread_pool_get_max_unused_threads () == MAX_UNUSED_THREADS);   
  g_assert (g_thread_pool_get_max_idle_time () == interval);

  for (i = 0; i < limit; i++) {
    g_thread_pool_push (idle_pool, GUINT_TO_POINTER (i + 1), NULL); 
    DEBUG_MSG (("[idle] ===> pushed new thread with id:%d, "
		"number of threads:%d, unprocessed:%d",
		i,
		g_thread_pool_get_num_threads (idle_pool),
		g_thread_pool_unprocessed (idle_pool)));
  }

  g_timeout_add ((interval - 1000),
		 test_thread_idle_timeout, 
		 GUINT_TO_POINTER (interval));
}
Пример #3
0
static void
_gck_call_base_finalize (GckCallClass *klass)
{
	GMainContext *context;
	GSource *src;

	if (klass->thread_pool) {
		g_assert (g_thread_pool_unprocessed (klass->thread_pool) == 0);
		g_thread_pool_free (klass->thread_pool, FALSE, TRUE);
		klass->thread_pool = NULL;
	}

	if (klass->completed_id) {
		context = g_main_context_default ();
		g_return_if_fail (context);

		src = g_main_context_find_source_by_id (context, klass->completed_id);
		g_assert (src);
		g_source_destroy (src);
		klass->completed_id = 0;
	}

	if (klass->completed_queue) {
		g_assert (g_async_queue_length (klass->completed_queue));
		g_async_queue_unref (klass->completed_queue);
		klass->completed_queue = NULL;
	}
}
Пример #4
0
DpPopulation*dp_evaluation_population_init(DpEvaluationCtrl*hevalctrl, int size, double noglobal_eps)
{
	DpPopulation*pop;
	int i, istart = 0;
	//gboolean immediate_stop = FALSE;
	gboolean immediate_stop = TRUE;
	//gboolean wait_finish = TRUE;
	gboolean wait_finish = FALSE;
	GError *gerror = NULL;
	GMainContext *gcontext = g_main_context_default();
	gulong microseconds = G_USEC_PER_SEC / 1000;
	pop = dp_population_new(size, hevalctrl->eval->size, hevalctrl->eval_target->size, hevalctrl->eval_target->precond_size, hevalctrl->seed);
	if ( noglobal_eps == 0 ) {
		dp_evaluation_individ_set(hevalctrl, pop->individ[0]);
		pop->individ[0]->user_data = dp_target_eval_get_user_data(hevalctrl->eval_target);
		istart = 1;
		pop->individ[0]->cost = G_MAXDOUBLE;
	}
	for ( i = istart; i < size; i++) {
		dp_evaluation_individ_scramble(hevalctrl, pop->individ[i], noglobal_eps);
		pop->individ[i]->user_data = dp_target_eval_get_user_data(hevalctrl->eval_target);
		pop->individ[i]->cost = G_MAXDOUBLE;
	}
#ifdef MPIZE
/* MPI initialization steps */
	int world_id = 0, world_count = 1;
	MPI_Comm_size(MPI_COMM_WORLD, &world_count);
	MPI_Comm_rank(MPI_COMM_WORLD, &world_id);
	int ind_per_node = (int)ceil(pop->size / world_count);
	int ind_per_last_node = pop->size - ind_per_node * (world_count - 1);
	dp_population_mpi_distribute(pop, world_id, world_count);
#endif
	if ( hevalctrl->eval_max_threads > 0 ) {
		hevalctrl->gthreadpool = g_thread_pool_new ((GFunc) dp_evaluation_population_init_func, (gpointer) hevalctrl, hevalctrl->eval_max_threads, hevalctrl->exclusive, &gerror);
		if ( gerror != NULL ) {
			g_error("%s", gerror->message);
		}
		for ( i = pop->slice_a; i < pop->slice_b; i++) {
			g_thread_pool_push (hevalctrl->gthreadpool, (gpointer)(pop->individ[i]), &gerror);
			if ( gerror != NULL ) {
				g_error("%s", gerror->message);
			}
		}
		while(g_thread_pool_unprocessed (hevalctrl->gthreadpool) > 0) {
			g_main_context_iteration(gcontext, FALSE);
            g_usleep (microseconds);
        }
		g_thread_pool_free (hevalctrl->gthreadpool, immediate_stop, wait_finish);
	} else {
		for ( i = pop->slice_a; i < pop->slice_b; i++) {
			dp_evaluation_population_init_func ((gpointer)(pop->individ[i]), (gpointer) hevalctrl);
		}
	}
#ifdef MPIZE
	dp_population_mpi_gather(pop, world_id, world_count);
#endif
	dp_population_update(pop, 0, pop->size);
	return pop;
}
Пример #5
0
/*
 * wait one thread pool
 */
void wait_thread_pool(const char *name, GThreadPool *pool)
{
	gint count = 1;
	while (count) {
		count = g_thread_pool_unprocessed(pool);
		usleep(10000);
	}
	log_message(DEBUG, DEBUG_AREA_MAIN,
			"thread pool '%s' free", name);
}
static void
test_thread_sort (gboolean sort)
{
  GThreadPool *pool;
  guint limit;
  guint max_threads;
  gint i;

  limit = MAX_THREADS * 10;

  if (sort) {
    max_threads = 1;
  } else {
    max_threads = MAX_THREADS;
  }

  /* It is important that we only have a maximum of 1 thread for this
   * test since the results can not be guranteed to be sorted if > 1.
   * 
   * Threads are scheduled by the operating system and are executed at
   * random. It cannot be assumed that threads are executed in the
   * order they are created. This was discussed in bug #334943.
   */
  
  pool = g_thread_pool_new (test_thread_sort_entry_func, 
			    GINT_TO_POINTER (sort), 
			    max_threads, 
			    FALSE,
			    NULL);

  g_thread_pool_set_max_unused_threads (MAX_UNUSED_THREADS); 

  if (sort) {
    g_thread_pool_set_sort_function (pool, 
				     test_thread_sort_compare_func,
				     GUINT_TO_POINTER (69));
  }
  
  for (i = 0; i < limit; i++) {
    guint id;

    id = g_random_int_range (1, limit) + 1;
    g_thread_pool_push (pool, GUINT_TO_POINTER (id), NULL);
    DEBUG_MSG (("%s ===> pushed new thread with id:%d, number "
		"of threads:%d, unprocessed:%d",
		sort ? "[  sorted]" : "[unsorted]", 
		id, 
		g_thread_pool_get_num_threads (pool),
		g_thread_pool_unprocessed (pool)));
  }

  g_assert (g_thread_pool_get_max_threads (pool) == max_threads);
  g_assert (g_thread_pool_get_num_threads (pool) == g_thread_pool_get_max_threads (pool));
}
Пример #7
0
Файл: vm.c Проект: jgraef/PUSH
push_int_t push_vm_num_queued(push_vm_t *vm) {
  push_int_t num;

  g_return_val_if_null(vm, 0);

  g_mutex_lock(vm->mutex);
  num = g_thread_pool_unprocessed(vm->threads);
  g_mutex_unlock(vm->mutex);

  return num;
}
Пример #8
0
int
main (int argc, char **argv)
{
	midgard_init ();	

	MidgardConfig *config = midgard_config_new ();
	midgard_config_read_file_at_path (config, "/tmp/test_SQLITE.conf", NULL);

	MidgardConnection *mgd = midgard_connection_new ();
	midgard_connection_open_config (mgd, config);

	GThreadPool *pool = g_thread_pool_new (pool_func, (gpointer) mgd, 10, TRUE, NULL);


	//midgard_storage_create_base_storage (mgd);
	//midgard_storage_create (mgd,"midgard_snippetdir");
	
	g_print ("START OPERATIONS \n");

	MidgardObject *obj = midgard_object_new (mgd, "midgard_snippetdir", NULL);
	g_thread_pool_push (pool, (gpointer) obj, NULL);

	MidgardObject *obja = midgard_object_new (mgd, "midgard_snippetdir", NULL);
	g_thread_pool_push (pool, (gpointer) obja, NULL);

	MidgardObject *objb = midgard_object_new (mgd, "midgard_snippetdir", NULL);
	g_thread_pool_push (pool, (gpointer) objb, NULL);
	
	MidgardObject *objc = midgard_object_new (mgd, "midgard_snippetdir", NULL);
	g_thread_pool_push (pool, (gpointer) objc, NULL);
	
	MidgardObject *objd = midgard_object_new (mgd, "midgard_snippetdir", NULL);
	g_thread_pool_push (pool, (gpointer) objd, NULL);

	g_print ("END OPERATIONS \n");

	g_print ("THREADS REMAIN (%d) \n", g_thread_pool_unprocessed (pool));	

	g_thread_pool_free (pool, FALSE, TRUE);

	return 0;
}
static gboolean 
test_thread_idle_timeout (gpointer data)
{
  guint interval;
  gint i;

  interval = GPOINTER_TO_UINT (data);
  
  for (i = 0; i < 2; i++) {
    g_thread_pool_push (idle_pool, GUINT_TO_POINTER (100 + i), NULL); 
    DEBUG_MSG (("[idle] ===> pushed new thread with id:%d, number "
		"of threads:%d, unprocessed:%d",
		100 + i, 
		g_thread_pool_get_num_threads (idle_pool),
		g_thread_pool_unprocessed (idle_pool)));
  }
  

  return FALSE;
}
Пример #10
0
static void
camel_session_finalise (CamelObject *o)
{
	CamelSession *session = (CamelSession *)o;
	GThreadPool *thread_pool = session->priv->thread_pool;

	g_hash_table_destroy(session->priv->thread_active);

	if (thread_pool != NULL) {
		/* there should be no unprocessed tasks */
		g_assert(g_thread_pool_unprocessed (thread_pool) == 0);
		g_thread_pool_free(thread_pool, FALSE, FALSE);
	}

	g_free(session->storage_path);

	g_mutex_free(session->priv->lock);
	g_mutex_free(session->priv->thread_lock);
	if (session->priv->junk_headers) {
		g_hash_table_remove_all (session->priv->junk_headers);
		g_hash_table_destroy (session->priv->junk_headers);
	}
	g_free(session->priv);
}
Пример #11
0
/**
 * Function called every second to cleanup things:
 *   - remove old connections
 *   - refresh ACL cache
 *   - refresh localid auth cache
 *   - refresh limited connection
 */
void main_cleanup()
{
	struct cache_message *cmessage;
	struct internal_message *int_message;

	/* remove old connections */
	clean_connections_list();

	/* info message about thread pools */
	if (DEBUG_OR_NOT(DEBUG_LEVEL_INFO, DEBUG_AREA_MAIN)) {
		if (g_thread_pool_unprocessed(nuauthdatas->user_workers)
		    || g_thread_pool_unprocessed(nuauthdatas->
						 acl_checkers)
		    || g_thread_pool_unprocessed(nuauthdatas->
						 user_loggers)) {
			g_message
			    ("%u user/%u acl/%u log unassigned task(s), %d "
			     "connection(s)",
			     g_thread_pool_unprocessed(nuauthdatas->
						       user_workers),
			     g_thread_pool_unprocessed(nuauthdatas->
						       acl_checkers),
			     g_thread_pool_unprocessed(nuauthdatas->
						       user_loggers),
			     g_hash_table_size(conn_list)
			    );
		}
	}

	act_on_loggers_processing();

	if (nuauthconf->acl_cache) {
		/* send refresh message to acl cache thread */
		cmessage = g_new0(struct cache_message, 1);
		cmessage->type = REFRESH_MESSAGE;
		g_async_queue_push(nuauthdatas->acl_cache->queue,
				   cmessage);
	}
static gboolean
test_check_start_and_stop (gpointer user_data)
{
  static guint test_number = 0;
  static gboolean run_next = FALSE;
  gboolean continue_timeout = TRUE;
  gboolean quit = TRUE;

  if (test_number == 0) {
    run_next = TRUE;
    DEBUG_MSG (("***** RUNNING TEST %2.2d *****", test_number)); 
  }
   
  if (run_next) {
    test_number++;

    switch (test_number) {
    case 1:
      test_thread_functions ();
      break;
    case 2:
      test_thread_stop_unused ();
      break;
    case 3:
      test_thread_pools ();   
      break;
    case 4:
      test_thread_sort (FALSE);  
      break;
    case 5:
      test_thread_sort (TRUE);  
      break;
    case 6:
      test_thread_idle_time ();   
      break;
    default:
      DEBUG_MSG (("***** END OF TESTS *****")); 
      g_main_loop_quit (main_loop);
      continue_timeout = FALSE;
      break;
    }

    run_next = FALSE;
    return TRUE;
  }

  if (test_number == 3) {
    G_LOCK (thread_counter_pools); 
    quit &= running_thread_counter <= 0;
    DEBUG_MSG (("***** POOL RUNNING THREAD COUNT:%ld", 
		running_thread_counter)); 
    G_UNLOCK (thread_counter_pools); 
  }

  if (test_number == 4 || test_number == 5) {
    G_LOCK (thread_counter_sort);
    quit &= sort_thread_counter <= 0;
    DEBUG_MSG (("***** POOL SORT THREAD COUNT:%ld", 
		sort_thread_counter)); 
    G_UNLOCK (thread_counter_sort); 
  }

  if (test_number == 6) {
    guint idle;

    idle = g_thread_pool_get_num_unused_threads ();
    quit &= idle < 1;
    DEBUG_MSG (("***** POOL IDLE THREAD COUNT:%d, UNPROCESSED JOBS:%d",
		idle, g_thread_pool_unprocessed (idle_pool)));
  }    

  if (quit) {
    run_next = TRUE;
  }

  return continue_timeout;
}