@@ -130,7 +130,7 @@ parallel_exec_prog(const char *log_file, const char *opt_log_file,
130
130
/* fork failed */
131
131
pg_log (PG_FATAL , "could not create worker process: %s\n" , strerror (errno ));
132
132
#else
133
- /* use first empty array element */
133
+ /* empty array element are always at the end */
134
134
new_arg = exec_thread_args [parallel_jobs - 1 ];
135
135
136
136
/* Can only pass one pointer into the function, so use a struct */
@@ -244,7 +244,7 @@ parallel_transfer_all_new_dbs(DbInfoArr *old_db_arr, DbInfoArr *new_db_arr,
244
244
/* fork failed */
245
245
pg_log (PG_FATAL , "could not create worker process: %s\n" , strerror (errno ));
246
246
#else
247
- /* use first empty array element */
247
+ /* empty array element are always at the end */
248
248
new_arg = transfer_thread_args [parallel_jobs - 1 ];
249
249
250
250
/* Can only pass one pointer into the function, so use a struct */
@@ -339,10 +339,10 @@ reap_child(bool wait_for_child)
339
339
thread_handles [thread_num ] = thread_handles [parallel_jobs - 1 ];
340
340
341
341
/*
342
- * We must swap the arg struct pointers because the thread we just
343
- * moved is active, and we must make sure it is not reused by the next
344
- * created thread. Instead, the new thread will use the arg struct of
345
- * the thread that just died .
342
+ * Move last active thead arg struct into the now-dead slot,
343
+ * and the now-dead slot to the end for reuse by the next thread.
344
+ * Though the thread struct is in use by another thread, we can
345
+ * safely swap the struct pointers within the array .
346
346
*/
347
347
tmp_args = cur_thread_args [thread_num ];
348
348
cur_thread_args [thread_num ] = cur_thread_args [parallel_jobs - 1 ];
0 commit comments