static int async_init (SeafObjStore *obj_store, CEventManager *ev_mgr) { GError *error = NULL; obj_store->ev_mgr = ev_mgr; obj_store->read_tpool = g_thread_pool_new (reader_thread, obj_store, MAX_READER_THREADS, FALSE, &error); if (error) { g_warning ("Failed to start reader thread pool: %s.\n", error->message); g_clear_error (&error); return -1; } obj_store->readers = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, g_free); obj_store->read_ev_id = cevent_manager_register (ev_mgr, on_read_done, obj_store); obj_store->write_tpool = g_thread_pool_new (writer_thread, obj_store, MAX_WRITER_THREADS, FALSE, &error); if (error) { g_warning ("Failed to start writer thread pool: %s.\n", error->message); g_clear_error (&error); return -1; } obj_store->writers = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, g_free); obj_store->write_ev_id = cevent_manager_register (ev_mgr, on_write_done, obj_store); obj_store->stat_tpool = g_thread_pool_new (stat_thread, obj_store, MAX_STAT_THREADS, FALSE, &error); if (error) { g_warning ("Failed to start statr thread pool: %s.\n", error->message); g_clear_error (&error); return -1; } obj_store->stats = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, g_free); obj_store->stat_ev_id = cevent_manager_register (ev_mgr, on_stat_done, obj_store); return 0; }
void li_tasklet_pool_set_threads(liTaskletPool *pool, gint threads) { if (threads < 0) threads = -1; if (pool->threads == threads) return; if (NULL != pool->threadpool) { if (pool->threads > 0 && threads > 0) { /* pool was exclusive, stays exlusive. just change number of threads */ g_thread_pool_set_max_threads(pool->threadpool, threads, NULL); pool->threads = g_thread_pool_get_num_threads(pool->threadpool); /* as we already had exclusive threads running, pool->threads should be > 0 */ return; } /* stop old pool */ g_thread_pool_free(pool->threadpool, FALSE, TRUE); pool->threadpool = NULL; } if (threads != 0) { pool->threadpool = g_thread_pool_new(run_tasklet, pool, threads, (threads > 0), NULL); if (threads > 0) { /* exclusive pool, see how many threads we got */ threads = g_thread_pool_get_num_threads(pool->threadpool); if (threads == 0) { /* couldn't get exlusive threads, share threads instead */ g_thread_pool_free(pool->threadpool, FALSE, TRUE); pool->threadpool = g_thread_pool_new(run_tasklet, pool, -1, FALSE, NULL); threads = -1; } } } pool->threads = threads; }
void _ide_thread_pool_init (gboolean is_worker) { gint compiler = COMPILER_MAX_THREADS; gint indexer = INDEXER_MAX_THREADS; gboolean shared = FALSE; if (is_worker) { compiler = 1; indexer = 1; shared = TRUE; } /* * Create our thread pool exclusive to compiler tasks (such as those from Clang). * We don't want to consume threads fro other GTask's such as those regarding IO so we manage * these work items exclusively. */ thread_pools [IDE_THREAD_POOL_COMPILER] = g_thread_pool_new (ide_thread_pool_worker, NULL, compiler, shared, NULL); /* * Create our pool exclusive to things like indexing. Such examples including building of * ctags indexes or highlight indexes. */ thread_pools [IDE_THREAD_POOL_INDEXER] = g_thread_pool_new (ide_thread_pool_worker, NULL, indexer, shared, NULL); }
int emc_init_server(struct emc_server_context *ctx) { int result; int max_workers; char *emc_data_file; g_thread_init(NULL); max_workers = emc_config_table_get_or_default_int("emc_max_workers", EMC_DEFAULT_MAX_WORKERS); emc_data_file = emc_config_table_get("emc_data_file"); ctx->nuauth_directory = g_tree_new( emc_netmask_order_func ); result = emc_parse_datafile(ctx, emc_data_file); if (result < 0) { return -1; } loop = ev_default_loop(0); result = emc_setup_servers(loop, ctx); if (result < 0) { return -1; } ev_signal_init(&sigint_watcher, sigint_cb, SIGINT); ev_signal_start(loop, &sigint_watcher); ev_signal_init(&sigterm_watcher, sigint_cb, SIGTERM); ev_signal_start(loop, &sigterm_watcher); ev_signal_init(&sigusr1_watcher, sigusr1_cb, SIGUSR1); ev_signal_start(loop, &sigusr1_watcher); ev_async_init(&client_ready_signal, emc_client_ready_cb); ev_async_start(loop, &client_ready_signal); ctx->continue_processing = 1; sigint_watcher.data = ctx; sigterm_watcher.data = ctx; sigusr1_watcher.data = ctx; client_ready_signal.data = ctx; g_thread_pool_set_max_unused_threads( (int)(max_workers/2) ); ctx->pool_tls_handshake = g_thread_pool_new((GFunc)emc_worker_tls_handshake, NULL, max_workers, FALSE, NULL); ctx->pool_reader = g_thread_pool_new((GFunc)emc_worker_reader, NULL, max_workers, FALSE, NULL); ctx->work_queue = g_async_queue_new(); ctx->tls_client_list_mutex = g_mutex_new(); log_printf(DEBUG_LEVEL_DEBUG, "Max: %d", g_thread_pool_get_max_unused_threads()); return 0; }
static void test_thread_pools (void) { GThreadPool *pool1, *pool2, *pool3; guint runs; guint i; pool1 = g_thread_pool_new ((GFunc)test_thread_pools_entry_func, NULL, 3, FALSE, NULL); pool2 = g_thread_pool_new ((GFunc)test_thread_pools_entry_func, NULL, 5, TRUE, NULL); pool3 = g_thread_pool_new ((GFunc)test_thread_pools_entry_func, NULL, 7, TRUE, NULL); runs = 300; for (i = 0; i < runs; i++) { g_thread_pool_push (pool1, GUINT_TO_POINTER (i + 1), NULL); g_thread_pool_push (pool2, GUINT_TO_POINTER (i + 1), NULL); g_thread_pool_push (pool3, GUINT_TO_POINTER (i + 1), NULL); leftover_task_counter += 3; } g_thread_pool_free (pool1, TRUE, TRUE); g_thread_pool_free (pool2, FALSE, TRUE); g_thread_pool_free (pool3, FALSE, TRUE); g_assert (runs * 3 == abs_thread_counter + leftover_task_counter); g_assert (running_thread_counter == 0); }
void download_init() { // create a thread pool download_pool = g_thread_pool_new((GFunc) download_send_accept, NULL, 10, FALSE, NULL); upload_pool = g_thread_pool_new((GFunc) download_recv_fetch, NULL, 10, FALSE, NULL); }
/* Filesystem-level operations. A filesystem is like a directory tree that we * are willing to export. */ BlueSkyFS *bluesky_new_fs(gchar *name) { BlueSkyFS *fs = g_new0(BlueSkyFS, 1); fs->lock = g_mutex_new(); fs->name = g_strdup(name); fs->inodes = g_hash_table_new(bluesky_fs_key_hash_func, bluesky_fs_key_equal_func); fs->next_inum = BLUESKY_ROOT_INUM + 1; fs->store = bluesky_store_new("file"); fs->flushd_lock = g_mutex_new(); fs->flushd_cond = g_cond_new(); fs->locations = g_hash_table_new(bluesky_cloudlog_hash, bluesky_cloudlog_equal); fs->inode_map = g_sequence_new(NULL); fs->log_state = g_new0(BlueSkyCloudLogState, 1); fs->log_state->data = g_string_new(""); fs->log_state->latest_cleaner_seq_seen = -1; fs->log_state->uploads_pending_lock = g_mutex_new(); fs->log_state->uploads_pending_cond = g_cond_new(); bluesky_cloudlog_threads_init(fs); fs->inode_fetch_thread_pool = g_thread_pool_new(inode_fetch_task, NULL, bluesky_max_threads, FALSE, NULL); return fs; }
int v9fs_init_worker_threads(void) { int ret = 0; V9fsThPool *p = &v9fs_pool; sigset_t set, oldset; sigfillset(&set); /* Leave signal handling to the iothread. */ pthread_sigmask(SIG_SETMASK, &set, &oldset); p->pool = g_thread_pool_new(v9fs_thread_routine, p, -1, FALSE, NULL); if (!p->pool) { ret = -1; goto err_out; } p->completed = g_async_queue_new(); if (!p->completed) { /* * We are going to terminate. * So don't worry about cleanup */ ret = -1; goto err_out; } event_notifier_init(&p->e, 0); event_notifier_set_handler(&p->e, v9fs_qemu_process_req_done); err_out: pthread_sigmask(SIG_SETMASK, &oldset, NULL); return ret; }
void pocketvox_controller_start(PocketvoxController *controller) { GList* modules = NULL; gint i, n_threads; GThreadPool *thread_pool = NULL; g_return_if_fail(NULL != controller); controller->priv = G_TYPE_INSTANCE_GET_PRIVATE (controller, TYPE_POCKETVOX_CONTROLLER, PocketvoxControllerPrivate); PocketvoxControllerPrivate *priv = controller->priv; modules = g_hash_table_get_values(priv->modules); //create a GThreadPool to make dictionnaries loading smoother n_threads = g_get_num_processors(); thread_pool = g_thread_pool_new((GFunc)pocketvox_module_build_dictionnary, NULL, n_threads, TRUE, NULL); for(i = 0; i < g_list_length(modules); i++) { g_thread_pool_push(thread_pool, (PocketvoxModule *)g_list_nth_data(modules, i), NULL); //pocketvox_module_build_dictionnary((PocketvoxModule *)g_list_nth_data(modules, i)); } g_thread_pool_free(thread_pool, FALSE, TRUE); g_list_free(modules); priv->loop = g_main_loop_new(NULL, FALSE); g_main_loop_run(priv->loop); }
static void _gck_call_base_init (GckCallClass *klass) { GckCallSource *source; GMainContext *context; GError *err = NULL; klass->thread_pool = g_thread_pool_new ((GFunc)process_async_call, klass, 16, FALSE, &err); if (!klass->thread_pool) { g_critical ("couldn't create thread pool: %s", err && err->message ? err->message : ""); return; } klass->completed_queue = g_async_queue_new_full (g_object_unref); g_assert (klass->completed_queue); context = g_main_context_default (); g_assert (context); /* Add our idle handler which processes other tasks */ source = (GckCallSource*)g_source_new (&completed_functions, sizeof (GckCallSource)); source->klass = klass; klass->completed_id = g_source_attach ((GSource*)source, context); g_source_set_callback ((GSource*)source, NULL, NULL, NULL); g_source_unref ((GSource*)source); }
int main (int argc, char **argv) { int i, start; GThreadPool *pool; g_type_init (); if (!g_thread_supported ()) g_thread_init (NULL); g_log_set_always_fatal (G_LOG_LEVEL_WARNING | G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL); if (argc == 1) usage(); start = 1; if (strcmp (argv[1], "--verbose") == 0) { verbose = TRUE; start = 2; } pool = g_thread_pool_new (load_image, NULL, 20, FALSE, NULL); i = start; while (1) { i++; if (i == argc) i = start; g_thread_pool_push (pool, argv[i], NULL); } return 0; }
ThreadedTimer::ThreadedTimer(int base_frequency): _terminate(false), _next_id(1) { // Wait time in microseconds. _wait_time= 1000 * 1000 / base_frequency; _thread= base::create_thread(start, this); _pool= g_thread_pool_new((GFunc) pool_function, this, WORKER_THREAD_COUNT, FALSE, NULL); }
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)); }
void dp_deep_step(DpDeepInfo*hdeepinfo) { int individ_id; gboolean immediate_stop = FALSE; gboolean wait_finish = TRUE; DpPopulation*population = hdeepinfo->population; DpPopulation*trial = hdeepinfo->trial; GError *gerror = NULL; if ( hdeepinfo->max_threads > 0 ) { if (hdeepinfo->gthreadpool == NULL) { hdeepinfo->gthreadpool = g_thread_pool_new ((GFunc) dp_deep_step_func, (gpointer) hdeepinfo, hdeepinfo->max_threads, hdeepinfo->exclusive, &gerror); } if ( gerror != NULL ) { g_error("%s", gerror->message); } for ( individ_id = 0; individ_id < population->size; individ_id++ ) { g_thread_pool_push (hdeepinfo->gthreadpool, GINT_TO_POINTER(individ_id + 1), &gerror); if ( gerror != NULL ) { g_error("%s", gerror->message); } } g_thread_pool_free (hdeepinfo->gthreadpool, immediate_stop, wait_finish); hdeepinfo->gthreadpool = NULL; } else { for ( individ_id = 0; individ_id < population->size; individ_id++ ) { dp_deep_step_func (GINT_TO_POINTER(individ_id + 1), (gpointer) hdeepinfo); } } dp_population_update(trial, 0, trial->size); trial->iter = population->iter + 1; hdeepinfo->population = trial; hdeepinfo->trial = population; }
/** * @brief Resume (or start) an RTP session * * @param session_gen The session to resume or start * @param range_gen Pointer tp @ref RTSP_Range to start with * * @todo This function should probably take care of starting eventual * libev events when the scheduler is replaced. * * This function is used by the PLAY method of RTSP to start or resume * a session; since a newly-created session starts as paused, this is * the only method available. * * The use of a pointer to double rather than a double itself is to * make it possible to pass this function straight to foreach * functions from glib. * * @internal This function should only be called from g_slist_foreach. */ static void rtp_session_resume(gpointer session_gen, gpointer range_gen) { RTP_session *session = (RTP_session*)session_gen; RTSP_Range *range = (RTSP_Range*)range_gen; fnc_log(FNC_LOG_VERBOSE, "Resuming session %p\n", session); session->range = range; session->start_seq = 1 + session->seq_no; session->start_rtptime = g_random_int(); session->send_time = 0.0; session->last_packet_send_time = time(NULL); /* Create the new thread pool for the read requests */ session->fill_pool = g_thread_pool_new(rtp_session_fill_cb, session, 1, true, NULL); /* Prefetch frames */ rtp_session_fill(session); ev_periodic_set(&session->transport.rtp_writer, range->playback_time - 0.05, 0, NULL); ev_periodic_start(session->srv->loop, &session->transport.rtp_writer); ev_io_start(session->srv->loop, &session->transport.rtcp_reader); }
/** * Initialize scheduler component: * * setup a thread pool * * allow global and local limits * * use globale limit only if ESDM_ACCESSIBILITY_GLOBAL is set (data_accessibility_t enum) * * */ esdm_scheduler_t* esdm_scheduler_init(esdm_instance_t* esdm) { ESDM_DEBUG(__func__); esdm_scheduler_t* scheduler = NULL; scheduler = (esdm_scheduler_t*) malloc(sizeof(esdm_scheduler_t)); // create thread pools per device // decide how many threads should be used per backend. const int ppn = esdm->procs_per_node; const int gt = esdm->total_procs; GError * error; for (int i = 0; i < esdm->modules->backend_count; i++) { esdm_backend* b = esdm->modules->backends[i]; // in total we should not use more than max_global total threads int max_local = (b->config->max_threads_per_node + ppn - 1) / ppn; int max_global = (b->config->max_global_threads + gt - 1) / gt; if (b->config->data_accessibility == ESDM_ACCESSIBILITY_GLOBAL){ b->threads = max_local < max_global ? max_local : max_global; }else{ b->threads = max_local; } DEBUG("Using %d threads for backend %s", b->threads, b->config->id); if (b->threads == 0){ b->threadPool = NULL; }else{ b->threadPool = g_thread_pool_new((GFunc)(backend_thread), b, b->threads, 1, & error); } } esdm->scheduler = scheduler; return scheduler; }
static __inline__ void rtp_session_resume_stored(RTP_session *rtp_s) { GEvent *periodic; if (rtp_s->playing) return; if (rtp_s->track && rtp_s->track->properties.media_type != MP_video) {//只创建一路audio是一个bug. rtp_s->track->parent->audio_rtp = rtp_s; return; } if (!rtp_s->fill_pool) { rtp_s->fill_pool = g_thread_pool_new(rtp_session_fill_cb, rtp_s, 1, TRUE, NULL); rtp_session_fill(rtp_s); } if (!rtp_s->transport.rtp_writer) { periodic = g_event_new(sizeof(RTP_writer), -1, 0); g_event_set_timeout(periodic, 1); g_event_set_callback(periodic, rtp_timer_cb, rtp_s, on_rtp_periodic_destroy); rtp_s->transport.rtp_writer = periodic; ((RTP_writer*)periodic)->rtp_s = rtp_s; rtp_session_ref(rtp_s); g_scheduler_add(periodic, LOOP_WEIGHT_VIDEO); } rtp_s->playing = TRUE; }
void fileops_empty_trash () { if (pool == NULL) { pool = g_thread_pool_new(_empty_trash_job, NULL, -1, FALSE, NULL); atexit(destroy_thread_pool); } GList* trash_list = NULL; GVolumeMonitor* vol_monitor = g_volume_monitor_get (); GList* mount_list = g_volume_monitor_get_mounts (vol_monitor); g_object_unref (vol_monitor); //iterate through all mounts GList* l; for (l = mount_list; l != NULL; l = l->next) { trash_list = g_list_concat (trash_list, _get_trash_dirs_for_mount (l->data)); } g_list_free_full (mount_list, g_object_unref); //add 'trash:' prefix trash_list = g_list_prepend (trash_list, g_file_new_for_uri ("trash:")); g_thread_pool_push(pool, trash_list, NULL); }
static void fm_job_init(FmJob *self) { /* create the thread pool if it doesn't exist. */ if( G_UNLIKELY(!thread_pool) ) thread_pool = g_thread_pool_new((GFunc)job_thread, NULL, -1, FALSE, NULL); ++n_jobs; }
int main(int argc, char **argv) { if (argc != 3) { fprintf(stderr, "usage: %s threadnum datanum\n", argv[0]); } else { int tn = 0, dn = 0, i; tn = atoi(argv[1]); dn = atoi(argv[2]); if (tn > 0) { cache = CMiniCache_alloc(400000, 500000, 400000, 5000, dfree); g_thread_init(NULL); GThreadPool *tp = g_thread_pool_new( test, &dn, tn, false, NULL); if (tp == NULL) { perror("can not initialize thread pool!"); exit(1); } int iarr[tn]; for (i=0; i<tn; i++) { iarr[i] = i+1; g_thread_pool_push(tp, &(iarr[i]), NULL); run ++; } while (run > 0); printf("done.\n"); } } return ret; }
/** * @brief Create the interface thread and thread pool that handle UI connections * * The GUI and the CLI use a socket connection to communicate with the * scheduler. This function creates the socket connection as well as everything * needed to handle incoming connections and messages. * * @note If interface_init() is called multiple times without a call to * interface_destroy(), it will become a no-op after the second call */ void interface_init(scheduler_t* scheduler) { if(!scheduler->i_created) { scheduler->i_created = 1; scheduler->i_terminate = 0; scheduler->cancel = NULL; scheduler->workers = g_thread_pool_new((GFunc)interface_thread, scheduler, CONF_interface_nthreads, FALSE, NULL); #if GLIB_MAJOR_VERSION >= 2 && GLIB_MINOR_VERSION >= 32 scheduler->server = g_thread_new("interface", (GThreadFunc)interface_listen_thread, scheduler); #else scheduler->server = g_thread_create((GThreadFunc)interface_listen_thread, scheduler, TRUE, NULL); #endif while(scheduler->cancel == NULL) usleep(100); } else { WARNING("Multiple attempts made to initialize the interface"); } }
static gpointer init_scheduler (gpointer arg) { if (job_thread_pool == NULL) { /* TODO: thread_pool_new can fail */ job_thread_pool = g_thread_pool_new (io_job_thread, NULL, 10, FALSE, NULL); if (job_thread_pool != NULL) { g_thread_pool_set_sort_function (job_thread_pool, g_io_job_compare, NULL); /* It's kinda weird that this is a global setting * instead of per threadpool. However, we really * want to cache some threads, but not keep around * those threads forever. */ g_thread_pool_set_max_idle_time (15 * 1000); g_thread_pool_set_max_unused_threads (2); } } return NULL; }
static gpointer lua_thread_main(gpointer data) { darktable.lua_state.pool = g_thread_pool_new(run_async_thread_main,NULL,-1,false,NULL); darktable.lua_state.loop = g_main_loop_new(darktable.lua_state.context,false); g_main_loop_run(darktable.lua_state.loop); return 0; }
static void default_prepare (GstTaskPool * pool, GError ** error) { GST_OBJECT_LOCK (pool); pool->pool = g_thread_pool_new ((GFunc) default_func, pool, -1, FALSE, NULL); GST_OBJECT_UNLOCK (pool); }
static void gst_dtls_connection_init (GstDtlsConnection * self) { GstDtlsConnectionPrivate *priv; self->priv = priv = gst_dtls_connection_get_instance_private (self); priv->ssl = NULL; priv->bio = NULL; priv->send_closure = NULL; priv->is_client = FALSE; priv->is_alive = TRUE; priv->keys_exported = FALSE; priv->bio_buffer = NULL; priv->bio_buffer_len = 0; priv->bio_buffer_offset = 0; g_mutex_init (&priv->mutex); g_cond_init (&priv->condition); /* Thread pool for handling timeouts, we only need one thread for that * really and share threads with all other thread pools around there as * this is not going to happen very often */ priv->thread_pool = g_thread_pool_new (handle_timeout, self, 1, FALSE, NULL); g_assert (priv->thread_pool); priv->timeout_pending = FALSE; }
void ToolsCorePool_Init(ToolsAppCtx *ctx) { gint maxThreads; GError *err = NULL; ToolsServiceProperty prop = { TOOLS_CORE_PROP_TPOOL }; gState.funcs.submit = ToolsCorePoolSubmit; gState.funcs.cancel = ToolsCorePoolCancel; gState.funcs.start = ToolsCorePoolStart; gState.ctx = ctx; maxThreads = g_key_file_get_integer(ctx->config, ctx->name, "pool.maxThreads", &err); if (err != NULL) { maxThreads = DEFAULT_MAX_THREADS; g_clear_error(&err); } if (maxThreads > 0) { gState.pool = g_thread_pool_new(ToolsCorePoolRunWorker, NULL, maxThreads, FALSE, &err); if (err == NULL) { #if GLIB_CHECK_VERSION(2, 10, 0) gint maxIdleTime; gint maxUnused; maxIdleTime = g_key_file_get_integer(ctx->config, ctx->name, "pool.maxIdleTime", &err); if (err != NULL || maxIdleTime <= 0) { maxIdleTime = DEFAULT_MAX_IDLE_TIME; g_clear_error(&err); } maxUnused = g_key_file_get_integer(ctx->config, ctx->name, "pool.maxUnusedThreads", &err); if (err != NULL || maxUnused < 0) { maxUnused = DEFAULT_MAX_UNUSED_THREADS; g_clear_error(&err); } g_thread_pool_set_max_idle_time(maxIdleTime); g_thread_pool_set_max_unused_threads(maxUnused); #endif } else { g_warning("error initializing thread pool, running single threaded: %s", err->message); g_clear_error(&err); } } gState.active = TRUE; gState.lock = g_mutex_new(); gState.threads = g_ptr_array_new(); gState.workQueue = g_queue_new(); ToolsCoreService_RegisterProperty(ctx->serviceObj, &prop); g_object_set(ctx->serviceObj, TOOLS_CORE_PROP_TPOOL, &gState.funcs, NULL); }
DpDeepInfo *dp_deep_info_init(DpEvaluation*heval, DpTarget*htarget, int worldid, int seed, double gamma_init, double roundoff_error, DpEvaluationStrategy eval_strategy, int population_size, double recombination_weight, double recombination_prob, double recombination_gamma, int es_lambda, int es_cutoff, double noglobal_eps, DpRecombinationStrategy recomb_strategy, gint max_threads) { GError *gerror = NULL; int i; DpDeepInfo*hdeepinfo = dp_deep_info_new(population_size, recombination_weight, recombination_prob, recombination_gamma, es_lambda, es_cutoff, noglobal_eps, max_threads); DpRecombinationStrategy strategy; hdeepinfo->hevalctrl = dp_evaluation_init(heval, htarget, worldid, seed, gamma_init, roundoff_error, max_threads, eval_strategy); hdeepinfo->trial = dp_population_new(hdeepinfo->population_size, hdeepinfo->hevalctrl->eval->size, hdeepinfo->hevalctrl->eval_target->size, hdeepinfo->hevalctrl->eval_target->precond_size, hdeepinfo->hevalctrl->seed + hdeepinfo->hevalctrl->yoffset); hdeepinfo->population = dp_evaluation_population_init(hdeepinfo->hevalctrl, hdeepinfo->population_size, hdeepinfo->noglobal_eps); hdeepinfo->recombination_control = dp_recombination_control_init(recomb_strategy, hdeepinfo->population, hdeepinfo->population->individ[0]->hrand, hdeepinfo->recombination_weight, hdeepinfo->recombination_prob, hdeepinfo->recombination_gamma); hdeepinfo->popunion = dp_population_union(hdeepinfo->population, hdeepinfo->trial); if ( hdeepinfo->max_threads > 0 ) { hdeepinfo->gthreadpool = g_thread_pool_new ((GFunc) dp_deep_evaluate_func, (gpointer) hdeepinfo, hdeepinfo->max_threads, hdeepinfo->exclusive, &gerror); if ( gerror != NULL ) { g_error("%s", gerror->message); } } for (i = 0; i < population_size; i++) { hdeepinfo->trial->individ[i]->user_data = hdeepinfo->population->individ[i]->user_data; } return hdeepinfo; }
/* * Each backend may have its own number of threads it works best */ void register_backends(int backend_count, int threads_per_backend){ pools = (GThreadPool **) malloc(sizeof (GThreadPool *) * backend_count); GError * error; for (int i=0; i < backend_count; i++){ pools[i] = g_thread_pool_new(backend_thread, (gpointer)(size_t) i, threads_per_backend, 1, & error); } }
void * thread_cachedir(void *cb_arg) { GHashTable *hash = cb_arg; GError *err = NULL; LOG(LOG_DEBUG, "entering thread"); if (! conf->sc_loop_delay || ! conf->sc_age_threshold) return NULL; pool = g_thread_pool_new(update_md, NULL, 50, FALSE, &err); if (err) { LOG(LOG_ERR, "can't init thread pool: %s", err->message); goto err; } while (1) { LOG(LOG_DEBUG, "updating cache directories"); g_hash_table_foreach(hash, cachedir_callback, hash); sleep(conf->sc_loop_delay); } err: return NULL; }
/* Initializes the games-sound support */ static void games_sound_init (void) { #if defined(HAVE_GSTREAMER) GError *err = NULL; g_assert (g_thread_supported ()); pipeline = gst_element_factory_make ("playbin", "playbin"); if (pipeline == NULL) return; threads = g_thread_pool_new ((GFunc) games_sound_thread_run, NULL, 10, FALSE, &err); sound_init = TRUE; #elif defined(HAVE_SDL_MIXER) const int audio_rate = MIX_DEFAULT_FREQUENCY; const int audio_format = MIX_DEFAULT_FORMAT; const int audio_channels = 2; const size_t buf_size = 1024; SDL_Init (SDL_INIT_AUDIO | SDL_INIT_NOPARACHUTE); if (Mix_OpenAudio (audio_rate, audio_format, audio_channels, buf_size) < 0) { _games_debug_print (GAMES_DEBUG_SOUND, "Error calling Mix_OpenAudio\n"); return; } #endif /* HAVE_SDL_MIXER */ }