+
+/*
+ * The description of pthread_create() is misleading, since it implies that
+ * threads will exit cleanly after their function returns.
+ *
+ * Since they do not (and the number of threads is limited by system
+ * resources), make a limited number of threads, and signal any that are
+ * waiting when we want a thread past that limit.
+ */
+static int
+start_drop(DATA * data)
+{
+ int rc;
+
+ if (!used_threads) {
+ /* mutex and condition for signalling thread */
+ pthread_mutex_init(&mutex_next_drop, NULL);
+ pthread_cond_init(&cond_next_drop, NULL);
+ }
+
+ if (used_threads < MAX_THREADS) {
+ rc = pthread_create(&(drop_threads[used_threads].myself),
+ NULL,
+ draw_drop,
+ data);
+ ++used_threads;
+ } else {
+ rc = put_next_drop();
+ }
+ return rc;
+}