+#ifdef USE_PTHREADS
+static bool
+quit_worm(int bitnum)
+{
+ pending |= (1 << bitnum);
+ napms(10); /* let the other thread(s) have a chance */
+ pending &= ~(1 << bitnum);
+ return quitting;
+}
+
+static void *
+start_worm(void *arg)
+{
+ unsigned long compare = 0;
+ Trace(("start_worm"));
+ while (!quit_worm(((struct worm *) arg) - worm)) {
+ while (compare < sequence) {
+ ++compare;
+#if HAVE_USE_WINDOW
+ use_window(stdscr, draw_worm, arg);
+#else
+ draw_worm(stdscr, arg);
+#endif
+ }
+ }
+ Trace(("...start_worm (done)"));
+ return NULL;
+}
+#endif
+
+static bool
+draw_all_worms(void)
+{
+ bool done = FALSE;
+ int n;
+ struct worm *w;
+
+#ifdef USE_PTHREADS
+ static bool first = TRUE;
+ if (first) {
+ first = FALSE;
+ for (n = 0, w = &worm[0]; n < number; n++, w++) {
+ (void) pthread_create(&(w->thread), NULL, start_worm, w);
+ }
+ }
+#else
+ for (n = 0, w = &worm[0]; n < number; n++, w++) {
+ if (
+#if HAVE_USE_WINDOW
+ USING_WINDOW2(stdscr, draw_worm, w)
+#else
+ draw_worm(stdscr, w)
+#endif
+ )
+ done = TRUE;
+ }
+#endif
+ return done;
+}
+