Skip to content

Commit

Permalink
Fix mc_select_children warning about non-existent children to wait for.
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.r-project.org/R/trunk@75467 00db46b3-68df-0310-9c12-caf00c1e9a41
  • Loading branch information
kalibera committed Oct 19, 2018
1 parent 9697c61 commit f9c0790
Showing 1 changed file with 28 additions and 7 deletions.
35 changes: 28 additions & 7 deletions src/library/parallel/src/fork.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
Derived from multicore version 0.1-8 by Simon Urbanek
*/
//#define MC_DEBUG
/* #define MC_DEBUG */

#ifdef HAVE_CONFIG_H
# include <config.h> /* for affinity function checks and sigaction */
Expand Down Expand Up @@ -766,21 +766,17 @@ SEXP mc_select_children(SEXP sTimeout, SEXP sWhich)
/* attached children have ci->pfd > 0 */
if (which) { /* check for the FD only if it's on the list */
unsigned int k = 0;
int found = 0;
while (k < wlen)
while (k < wlen) {
if (which[k++] == ci->pid) {
FD_SET(ci->pfd, &fs);
if (ci->pfd > maxfd) maxfd = ci->pfd;
#ifdef MC_DEBUG
Dprintf("select_children: added child %d (%d)\n", ci->pid, ci->pfd);
#endif
wcount++;
found = 1;
break;
}
if (!found)
/* FIXME: probably should be an error */
warning(_("cannot wait for child %d as it does not exist"), ci->pid);
}
} else {
/* not sure if this should be allowed */
FD_SET(ci->pfd, &fs);
Expand All @@ -793,6 +789,31 @@ SEXP mc_select_children(SEXP sTimeout, SEXP sWhich)
ci = ci->next;
}

if (which && wcount < wlen) {
/* children specified multiple times or not found */
for(unsigned int k = 0; k < wlen; k++) {
ci = children;
int found = 0;
while(ci) {
if (!ci->detached && ci->ppid == ppid &&
ci->pid == which[k] && FD_ISSET(ci->pfd, &fs)) {

found = 1;
break;
}
ci = ci->next;
}
if (!found) {
#ifdef MC_DEBUG
Dprintf("select_children: cannot wait for child %d (idx %d) as it does not exist\n",
which[k], k);
#endif
/* FIXME: probably should be an error */
warning(_("cannot wait for child %d as it does not exist"), which[k]);
}
}
}

#ifdef MC_DEBUG
Dprintf("select_children: maxfd=%d, wlen=%d, wcount=%d, timeout=%f\n", maxfd, wlen, wcount, timeout);
#endif
Expand Down

0 comments on commit f9c0790

Please sign in to comment.