/* fork failed */
pg_log(PG_FATAL, "could not create worker process: %s\n", strerror(errno));
#else
- /* use first empty array element */
+ /* empty array element are always at the end */
new_arg = exec_thread_args[parallel_jobs - 1];
/* Can only pass one pointer into the function, so use a struct */
/* fork failed */
pg_log(PG_FATAL, "could not create worker process: %s\n", strerror(errno));
#else
- /* use first empty array element */
+ /* empty array element are always at the end */
new_arg = transfer_thread_args[parallel_jobs - 1];
/* Can only pass one pointer into the function, so use a struct */
thread_handles[thread_num] = thread_handles[parallel_jobs - 1];
/*
- * We must swap the arg struct pointers because the thread we just
- * moved is active, and we must make sure it is not reused by the next
- * created thread. Instead, the new thread will use the arg struct of
- * the thread that just died.
+ * Move last active thead arg struct into the now-dead slot,
+ * and the now-dead slot to the end for reuse by the next thread.
+ * Though the thread struct is in use by another thread, we can
+ * safely swap the struct pointers within the array.
*/
tmp_args = cur_thread_args[thread_num];
cur_thread_args[thread_num] = cur_thread_args[parallel_jobs - 1];