1 /* This testcase is part of GDB, the GNU debugger.
3 Copyright 2012-2015 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>
32 /* Count the number of tasks/threads in the PID thread group. */
35 count_tasks (pid_t pid
)
41 snprintf (path
, sizeof (path
), "/proc/%d/task/", (int) pid
);
46 for (count
= 0; readdir (d
) != NULL
; count
++)
50 /* Account for '.' and '..'. */
55 pthread_attr_t attr
[CPU_SETSIZE
];
56 pthread_t thr
[CPU_SETSIZE
];
69 for (i
= 0; i
< CPU_SETSIZE
; i
++)
74 pthread_attr_init (&attr
[i
]);
75 CPU_ZERO_S (sizeof (set
), &set
);
76 CPU_SET_S (i
, sizeof (set
), &set
);
78 ret
= pthread_attr_setaffinity_np (&attr
[i
], sizeof (set
), &set
);
81 fprintf (stderr
, "set_affinity: %d: %s\n", ret
, strerror (ret
));
84 ret
= pthread_create (&thr
[i
], &attr
[i
], mythread
, NULL
);
85 /* Should fail with EINVAL at some point. */
90 fprintf (stderr
, "pthread_create: %d: %s\n", ret
, strerror (ret
));
92 /* Wait for all threads to exit. pthread_create spawns a
93 clone thread even in the failing case, as it can only try
94 to set the affinity after creating the thread. That new
95 thread is immediately canceled (because setting the
96 affinity fails), by killing it with a SIGCANCEL signal,
97 which may end up in pthread_cancel/unwind paths, which
98 may trigger a libgcc_s.so load, making the thread hit the
99 solib-event breakpoint. Now, if we would let the program
100 exit without waiting, sometimes it would happen that the
101 inferior exits just while we're handling the solib-event,
102 resulting in errors being thrown due to failing ptrace
103 call fails (with ESCHR), breaking the test. */
105 while (count_tasks (getpid ()) > 1)
113 /* Normal exit, because this is what we are expecting. */
118 /* Should not normally be reached. */
This page took 0.032461 seconds and 4 git commands to generate.