#define ENGINE_THREADS_INTERNAL #include "engine/threads.h" #include void threads_go(struct threads *handler) { int running_count = handler->running_count; for (int i = 0; i < running_count; i++) { __threads_args_init(handler->args + i, handler, i); pthread_create( handler->threads + i, NULL, i == 0 ? root_thread : child_thread, handler->args + i ); } } void *child_thread(void *_args) { struct child_thread_args *args = (struct child_thread_args*)_args; args->stop = 0; int depth = 0; engine_message_t *message = args->message->newest_valid; while (true) { message->depth = depth++; message->multipv = args->id; ipc_moves_init(&message->pv); // pseudo engine work for (volatile int k = 0; k < 1000000000; k++) {} add_ipc_move(&message->pv, (ipc_move_t) { 14, 24 }); if (args->stop || !should_continue(message, args->go_args)) { message->best_move = (ipc_move_t) { 12, 24 }; message->ponder = (ipc_move_t) { 42, 54 }; message->next = NULL; engine_message_mark_ready(message); break; } engine_message_mark_ready(message); message = engine_message_handler_push(args->message); } args->stop = 2; } // DTS requires a root thread which is initialize the search tree, and the // others who use that search tree. it's as if root_thread is the owner of the // tree void *root_thread(void *_args) { struct root_thread_args *args = (struct root_thread_args*)_args; args->stop = 0; }