@@ -87,6 +87,24 @@ parallel_exec_prog(const char *log_file, const char *opt_log_file,
8787{
8888/* parallel */
8989#ifdef WIN32
90+ if (thread_handles == NULL )
91+ thread_handles = pg_malloc (user_opts .jobs * sizeof (HANDLE ));
92+
93+ if (exec_thread_args == NULL )
94+ {
95+ int i ;
96+
97+ exec_thread_args = pg_malloc (user_opts .jobs * sizeof (exec_thread_arg * ));
98+
99+ /*
100+ * For safety and performance, we keep the args allocated during
101+ * the entire life of the process, and we don't free the args in a
102+ * thread different from the one that allocated it.
103+ */
104+ for (i = 0 ;i < user_opts .jobs ;i ++ )
105+ exec_thread_args [i ]= pg_malloc0 (sizeof (exec_thread_arg ));
106+ }
107+
90108cur_thread_args = (void * * )exec_thread_args ;
91109#endif
92110/* harvest any dead children */
@@ -112,24 +130,6 @@ parallel_exec_prog(const char *log_file, const char *opt_log_file,
112130/* fork failed */
113131pg_log (PG_FATAL ,"could not create worker process: %s\n" ,strerror (errno ));
114132#else
115- if (thread_handles == NULL )
116- thread_handles = pg_malloc (user_opts .jobs * sizeof (HANDLE ));
117-
118- if (exec_thread_args == NULL )
119- {
120- int i ;
121-
122- exec_thread_args = pg_malloc (user_opts .jobs * sizeof (exec_thread_arg * ));
123-
124- /*
125- * For safety and performance, we keep the args allocated during
126- * the entire life of the process, and we don't free the args in a
127- * thread different from the one that allocated it.
128- */
129- for (i = 0 ;i < user_opts .jobs ;i ++ )
130- exec_thread_args [i ]= pg_malloc0 (sizeof (exec_thread_arg ));
131- }
132-
133133/* use first empty array element */
134134new_arg = exec_thread_args [parallel_jobs - 1 ];
135135
@@ -196,6 +196,24 @@ parallel_transfer_all_new_dbs(DbInfoArr *old_db_arr, DbInfoArr *new_db_arr,
196196{
197197/* parallel */
198198#ifdef WIN32
199+ if (thread_handles == NULL )
200+ thread_handles = pg_malloc (user_opts .jobs * sizeof (HANDLE ));
201+
202+ if (transfer_thread_args == NULL )
203+ {
204+ int i ;
205+
206+ transfer_thread_args = pg_malloc (user_opts .jobs * sizeof (transfer_thread_arg * ));
207+
208+ /*
209+ * For safety and performance, we keep the args allocated during
210+ * the entire life of the process, and we don't free the args in a
211+ * thread different from the one that allocated it.
212+ */
213+ for (i = 0 ;i < user_opts .jobs ;i ++ )
214+ transfer_thread_args [i ]= pg_malloc0 (sizeof (transfer_thread_arg ));
215+ }
216+
199217cur_thread_args = (void * * )transfer_thread_args ;
200218#endif
201219/* harvest any dead children */
@@ -226,24 +244,6 @@ parallel_transfer_all_new_dbs(DbInfoArr *old_db_arr, DbInfoArr *new_db_arr,
226244/* fork failed */
227245pg_log (PG_FATAL ,"could not create worker process: %s\n" ,strerror (errno ));
228246#else
229- if (thread_handles == NULL )
230- thread_handles = pg_malloc (user_opts .jobs * sizeof (HANDLE ));
231-
232- if (transfer_thread_args == NULL )
233- {
234- int i ;
235-
236- transfer_thread_args = pg_malloc (user_opts .jobs * sizeof (transfer_thread_arg * ));
237-
238- /*
239- * For safety and performance, we keep the args allocated during
240- * the entire life of the process, and we don't free the args in a
241- * thread different from the one that allocated it.
242- */
243- for (i = 0 ;i < user_opts .jobs ;i ++ )
244- transfer_thread_args [i ]= pg_malloc0 (sizeof (transfer_thread_arg ));
245- }
246-
247247/* use first empty array element */
248248new_arg = transfer_thread_args [parallel_jobs - 1 ];
249249