--- jtwin.c 2026-09-21 22:02:57 +++ jtwin_hb.c 2026-09-23 12:50:28 @@ -233,11 +233,46 @@ static pthread_mutex_t g_mtx = PTHREAD_MUTEX_INITIALIZER; static long long g_nodes, g_fails; -static void *worker(void *arg) +/* ---- heartbeat instrumentation (this file only; jtwin.c is untouched) ---- + * A detached monitor thread reports the engine's OWN node counters, so a long refutation search is + * observable instead of silent. It reads each worker's Ctx->nodes (a benign race, a progress + * figure only) and never touches the search itself. */ +static Ctx *g_ctx[64]; +static volatile int g_ctx_live[64]; +static volatile int g_mon_stop, g_mon_gen; +static int g_hb_threads, g_hb_R; + +static void *hb_monitor(void *arg) { (void)arg; + int myR = g_hb_R, myGen = g_mon_gen; + double next = 10.0; + struct timespec t0, t1, s = { 1, 0 }; + clock_gettime(CLOCK_MONOTONIC, &t0); + for (;;) { + nanosleep(&s, NULL); + if (g_mon_stop || myGen != g_mon_gen) break; + clock_gettime(CLOCK_MONOTONIC, &t1); + double el = (t1.tv_sec - t0.tv_sec) + (t1.tv_nsec - t0.tv_nsec) / 1e9; + if (el >= next) { + long long total = 0; int live = 0; + for (int i = 0; i < g_hb_threads && i < 64; i++) + if (g_ctx_live[i] && g_ctx[i]) { total += g_ctx[i]->nodes; live++; } + fprintf(stderr, " HEARTBEAT R=%d t=%.0fs nodes=%lld rate=%.3g/s live=%d/%d branches=%d/%d found=%d\n", + myR, el, total, total / el, live, g_hb_threads, g_next, g_np0, g_found); + fflush(stderr); + next = el + 60.0; + } + } + return NULL; +} + +static void *worker(void *arg) +{ + int id = (int)(long)arg; Ctx *c = (Ctx *)malloc(sizeof(Ctx)); long long ln = 0, lf = 0; + if (id >= 0 && id < 64) { g_ctx[id] = c; g_ctx_live[id] = 1; } for (;;) { pthread_mutex_lock(&g_mtx); if (g_found || g_next >= g_np0) { pthread_mutex_unlock(&g_mtx); break; } @@ -258,6 +293,7 @@ pthread_mutex_lock(&g_mtx); g_nodes += ln; g_fails += lf; pthread_mutex_unlock(&g_mtx); + if (id >= 0 && id < 64) g_ctx_live[id] = 0; free(c); return NULL; } @@ -273,9 +309,14 @@ g_next = 0; g_found = 0; g_nodes = g_fails = 0; if (nthreads < 1) nthreads = 1; if (nthreads > g_np0) nthreads = g_np0; - pthread_t th[64]; - for (int i = 0; i < nthreads; i++) pthread_create(&th[i], NULL, worker, NULL); + g_hb_R = R; g_hb_threads = nthreads; g_mon_stop = 0; g_mon_gen++; + fprintf(stderr, " RUNG start R=%d threads=%d branches=%d\n", R, nthreads, g_np0); + fflush(stderr); + pthread_t th[64], mon; + if (pthread_create(&mon, NULL, hb_monitor, NULL) == 0) pthread_detach(mon); + for (int i = 0; i < nthreads; i++) pthread_create(&th[i], NULL, worker, (void *)(long)i); for (int i = 0; i < nthreads; i++) pthread_join(th[i], NULL); + g_mon_stop = 1; if (sol_out) memcpy(sol_out, (const void *)g_sol, sizeof(g_sol)); if (nodes_out) *nodes_out = g_nodes; if (fails_out) *fails_out = g_fails;