2 * Copyright 2008, Ingo Weinhold, ingo_weinhold@gmx.de.
3 * Distributed under the terms of the MIT License.
16 static int64 sHandledSignals
= 0;
20 signal_pusher(void* data
)
23 get_team_info(B_CURRENT_TEAM
, &teamInfo
);
24 thread_id mainThread
= teamInfo
.team
;
27 send_signal(mainThread
, SIGUSR1
);
36 signal_handler(int signal
)
46 const int testSeconds
= 2;
47 printf("Trying to provoke allocator deadlock in signal handler.\n");
48 printf("If successful test will finish in %d seconds...\n", testSeconds
);
50 // install signal handler
51 if (signal(SIGUSR1
, signal_handler
) == SIG_ERR
) {
52 fprintf(stderr
, "Error: Failed to install signal handler: %s\n",
57 // start signal thread
58 thread_id signalThread
= spawn_thread(&signal_pusher
, "signal pusher",
59 B_NORMAL_PRIORITY
, NULL
);
60 resume_thread(signalThread
);
62 bigtime_t endTime
= system_time() + 1000000 * (bigtime_t
)testSeconds
;
63 while (system_time() < endTime
) {
64 const int allocationCount
= 1000;
65 void* allocations
[allocationCount
];
66 for (int i
= 0; i
< allocationCount
; i
++)
67 allocations
[i
] = malloc(rand() % 50);
68 for (int i
= 0; i
< allocationCount
; i
++)
72 kill_thread(signalThread
);
75 printf("test successful, handled %" B_PRId64
" signals\n", sHandledSignals
);