1 /* This testcase is part of GDB, the GNU debugger.
3 Copyright 2012-2014 Free Software Foundation, Inc.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
27 #include <sys/types.h>
31 /* Count the number of tasks/threads in the PID thread group. */
34 count_tasks (pid_t pid
)
40 snprintf (path
, sizeof (path
), "/proc/%d/task/", (int) pid
);
45 for (count
= 0; readdir (d
) != NULL
; count
++)
49 /* Account for '.' and '..'. */
54 pthread_attr_t attr
[CPU_SETSIZE
];
55 pthread_t thr
[CPU_SETSIZE
];
68 for (i
= 0; i
< CPU_SETSIZE
; i
++)
73 pthread_attr_init (&attr
[i
]);
74 CPU_ZERO_S (sizeof (set
), &set
);
75 CPU_SET_S (i
, sizeof (set
), &set
);
77 ret
= pthread_attr_setaffinity_np (&attr
[i
], sizeof (set
), &set
);
80 fprintf (stderr
, "set_affinity: %d: %s\n", ret
, strerror (ret
));
83 ret
= pthread_create (&thr
[i
], &attr
[i
], mythread
, NULL
);
84 /* Should fail with EINVAL at some point. */
89 fprintf (stderr
, "pthread_create: %d: %s\n", ret
, strerror (ret
));
91 /* Wait for all threads to exit. pthread_create spawns a
92 clone thread even in the failing case, as it can only try
93 to set the affinity after creating the thread. That new
94 thread is immediately canceled (because setting the
95 affinity fails), by killing it with a SIGCANCEL signal,
96 which may end up in pthread_cancel/unwind paths, which
97 may trigger a libgcc_s.so load, making the thread hit the
98 solib-event breakpoint. Now, if we would let the program
99 exit without waiting, sometimes it would happen that the
100 inferior exits just while we're handling the solib-event,
101 resulting in errors being thrown due to failing ptrace
102 call fails (with ESCHR), breaking the test. */
104 while (count_tasks (getpid ()) > 1)
112 /* Normal exit, because this is what we are expecting. */
117 /* Should not normally be reached. */
This page took 0.030839 seconds and 4 git commands to generate.