1 // https://bugs.kde.org/show_bug.cgi?id=228343
7 #include <libkern/OSAtomic.h>
10 OSSpinLock sl
= OS_SPINLOCK_INIT
;
11 typedef void *(*worker_t
)(void*);
12 typedef void (*Sigaction
)(int, siginfo_t
*, void *);
16 static void EnableSigprof(Sigaction SignalHandler
) {
18 sa
.sa_sigaction
= SignalHandler
;
19 sa
.sa_flags
= SA_RESTART
| SA_SIGINFO
;
20 sigemptyset(&sa
.sa_mask
);
21 if (sigaction(SIGPROF
, &sa
, NULL
) != 0) {
25 struct itimerval timer
;
26 timer
.it_interval
.tv_sec
= 0;
27 timer
.it_interval
.tv_usec
= 1000000 / 10000;
28 timer
.it_value
= timer
.it_interval
;
29 if (setitimer(ITIMER_PROF
, &timer
, 0) != 0) {
37 for (i
= 0; i
< 100000000; i
++) {
38 void *x
= malloc((i
% 64) + 1);
44 void SignalHandlerWithSpinlock(int sig
, siginfo_t
*siginfo
, void *context
) {
47 OSSpinLockUnlock(&sl
);
51 EnableSigprof(SignalHandlerWithSpinlock
);
54 pthread_create(&w_1
, NULL
, Worker
, NULL
);
55 pthread_create(&w_2
, NULL
, Worker
, NULL
);
56 pthread_join(w_1
, NULL
);
57 pthread_join(w_2
, NULL
);
58 printf("\tGLOB=%d\n", GLOB
);