gochatai/pachi_py/pachi/uct/search.c
/* After it is started, it will update mctx->t to point at some tree
 * used for the actual search, on return
 * it will set mctx->games to the number of performed simulations. */
After it is started, it will update mctx->t to point at some tree
used for the actual search, on return
it will set mctx->games to the number of performed simulations.
After it is started it will update mctx - > t to point at some tree used for the actual search on return it will set mctx - > games to the number of performed simulations .
static void *
spawn_thread_manager(void *ctx_)
{
	struct uct_thread_ctx *mctx = ctx_;
	struct uct *u = mctx->u;
	struct tree *t = mctx->t;
	fast_srandom(mctx->seed);
	int played_games = 0;
	pthread_t threads[u->threads];
	int joined = 0;
	uct_halt = 0;
	if (u->pondering && t->nodes && t->nodes_size >= t->pruning_threshold) {
		t->root = tree_garbage_collect(t, t->root);
	}
	for (int ti = 0; ti < u->threads; ti++) {
		struct uct_thread_ctx *ctx = malloc2(sizeof(*ctx));
		ctx->u = u; ctx->b = mctx->b; ctx->color = mctx->color;
		mctx->t = ctx->t = t;
		ctx->tid = ti; ctx->seed = fast_random(65536) + ti;
		ctx->ti = mctx->ti;
		pthread_attr_t a;
		pthread_attr_init(&a);
		pthread_attr_setstacksize(&a, 1048576);
		pthread_create(&threads[ti], &a, spawn_worker, ctx);
		if (UDEBUGL(4))
			fprintf(stderr, "Spawned worker %d\n", ti);
	}
	while (joined < u->threads) {
		pthread_cond_wait(&finish_cond, &finish_mutex);
		if (finish_thread < 0) {
			uct_halt = 1;
			pthread_mutex_unlock(&finish_serializer);
			continue;
		}
		struct uct_thread_ctx *ctx;
		pthread_join(threads[finish_thread], (void **) &ctx);
		played_games += ctx->games;
		joined++;
		free(ctx);
		if (UDEBUGL(4))
			fprintf(stderr, "Joined worker %d\n", finish_thread);
		pthread_mutex_unlock(&finish_serializer);
	}
	pthread_mutex_unlock(&finish_mutex);
	mctx->games = played_games;
	return mctx;
}
static void * spawn_thread_manager ( void * ctx_ ) { struct uct_thread_ctx * mctx = ctx_ ; struct uct * u = mctx -> u ; struct tree * t = mctx -> t ; fast_srandom ( mctx -> seed ) ; int played_games = 0 ; pthread_t threads [ u -> threads ] ; int joined = 0 ; uct_halt = 0 ; if ( u -> pondering && t -> nodes && t -> nodes_size >= t -> pruning_threshold ) { t -> root = tree_garbage_collect ( t , t -> root ) ; } for ( int ti = 0 ; ti < u -> threads ; ti ++ ) { struct uct_thread_ctx * ctx = malloc2 ( sizeof ( * ctx ) ) ; ctx -> u = u ; ctx -> b = mctx -> b ; ctx -> color = mctx -> color ; mctx -> t = ctx -> t = t ; ctx -> tid = ti ; ctx -> seed = fast_random ( 65536 ) + ti ; ctx -> ti = mctx -> ti ; pthread_attr_t a ; pthread_attr_init ( & a ) ; pthread_attr_setstacksize ( & a , 1048576 ) ; pthread_create ( & threads [ ti ] , & a , spawn_worker , ctx ) ; if ( UDEBUGL ( 4 ) ) fprintf ( stderr , " \n " , ti ) ; } while ( joined < u -> threads ) { pthread_cond_wait ( & finish_cond , & finish_mutex ) ; if ( finish_thread < 0 ) { uct_halt = 1 ; pthread_mutex_unlock ( & finish_serializer ) ; continue ; } struct uct_thread_ctx * ctx ; pthread_join ( threads [ finish_thread ] , ( void * * ) & ctx ) ; played_games += ctx -> games ; joined ++ ; free ( ctx ) ; if ( UDEBUGL ( 4 ) ) fprintf ( stderr , " \n " , finish_thread ) ; pthread_mutex_unlock ( & finish_serializer ) ; } pthread_mutex_unlock ( & finish_mutex ) ; mctx -> games = played_games ; return mctx ; }
After it is started, it will update mctx->t to point at some tree
 used for the actual search, on return
 it will set mctx->games to the number of performed simulations.
After it is started it will update mctx - > t to point at some tree used for the actual search on return it will set mctx - > games to the number of performed simulations .
/* In thread_manager, we use only some of the ctx fields. */ /* Garbage collect the tree by preference when pondering. */ /* Spawn threads... */ /* ...and collect them back: */ /* Wait for some thread to finish... */ /* Stop-by-caller. Tell the workers to wrap up
			 * and unblock them from terminating. */ /* We need to make sure the workers do not complete
			 * the termination sequence before we get officially
			 * stopped - their wake and the stop wake could get
			 * coalesced. */ /* ...and gather its remnants. */