memcheck/tests/sh-mem-random.c: Set huge_addr to 240GB
[valgrind.git] / drd / tests / concurrent_close.cpp
blobe098dd37a5de4cceb24f96882c0c761098a42150
1 /*
2 * Reproducer for bug #323905. See also
3 * http://bugs.kde.org/show_bug.cgi?id=323905.
4 */
6 #include <climits> /* PTHREAD_STACK_MIN */
7 #include <cstdio> /* fprintf() */
8 #include <fcntl.h> /* O_RDONLY */
9 #include <pthread.h>
10 #include <unistd.h> /* close() */
11 #include "config.h"
13 /* Happens with two threads also */
14 #define THREAD_COUNT 256
16 void* thread(void*)
18 int fd;
20 /* Happens with any file, not just /dev/null */
21 fd = open("/dev/null", O_RDONLY);
22 if (fd >= 0)
23 close(fd);
24 else
25 fprintf(stderr, "Failed to open /dev/null\n");
26 return 0;
29 int main()
31 int i, r;
32 pthread_attr_t attr;
33 pthread_t threads[THREAD_COUNT];
35 pthread_attr_init(&attr);
36 #if !defined(VGO_freebsd)
37 pthread_attr_setstacksize(&attr, PTHREAD_STACK_MIN);
38 #endif
39 for (i = 0; i < THREAD_COUNT; ++i) {
40 r = pthread_create(&threads[i], &attr, thread, 0);
41 if (r != 0) {
42 fprintf(stderr, "Failed to create thread %d\n", i);
43 return 1;
46 pthread_attr_destroy(&attr);
47 for (i = 0; i < THREAD_COUNT; ++i) {
48 r = pthread_join(threads[i], 0);
49 if (r != 0) {
50 fprintf(stderr, "Failed to join thread %d\n", i);
51 return 1;
54 fprintf(stderr, "Done.\n");
55 return 0;