[racket] can custodian-shutdown-all interrupt an #:atomic callback?

From: John Clements (clements at brinckerhoff.org)
Date: Sat Sep 10 15:00:19 EDT 2011

On Sep 9, 2011, at 5:59 PM, Matthew Flatt wrote:

> At Fri, 9 Sep 2011 17:39:38 -0700, John Clements wrote:
>> It looks to me as though when a custodian-shutdown-all occurs, the
>> custodian actions associated using scheme_add_managed() can be
>> triggered while another thread is in the middle of a callback to an
>> FFI-generated callback that includes the #:atomic declaration. Is
>> this true? If true, is it only true for some certain set of
>> (avoidable) circumstances?
> 
> The possibility that comes to mind is a custodian shutdown triggered by
> a memory-use limit. It looks easy and sensible to disallow that.
> 
> Could that be what you saw, or should I look for other possibilities?

I believe it was a custodian-shutdown-all on a user thread triggered by clicking "run" in DrRacket.

However, looking more carefully at the stack trace below, I think I've misread it.

This dump came from a DrRacket hang (hence the SIGQUIT), and based on my reading of Apple CoreAudio documentation, it looks to me like the call in frame 11 of thread 0 to AudioUnitStop is waiting on a mutex which I'm guessing is held by thread 10, which I believe is the main audio processing thread.  The action in thread 0 is triggered by a custodian action, as shown by frame 27 of that thread.

Thread 10 is blocked, though. I initially believed it was in the middle of a callback, but looking more carefully, it now seems to me that it was blocked on a queue_callback, which surprises me, because I didn't think that a queue-callback could block. I suppose there has to be *some* synchronization in there, though.

If I'm reading this correctly, then the custodian-ness could be a red herring; it could be that any racket thread calling CloseStream or another audio function could cause this problem. If queue_callback can block, I'm not sure how to resolve this.

Many thanks for your help,

John




Process:         racket [60140]
Path:            /Users/clements/plt/bin/racket
Identifier:      racket
Version:         ??? (???)
Code Type:       X86-64 (Native)
Parent Process:  bash [35088]

Date/Time:       2011-09-08 16:08:26.985 -0700
OS Version:      Mac OS X 10.6.8 (10K549)
Report Version:  6

Exception Type:  EXC_CRASH (SIGQUIT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Crashed Thread:  0  Dispatch queue: com.apple.main-thread

Thread 0 Crashed:  Dispatch queue: com.apple.main-thread
0   libSystem.B.dylib             	0x00007fff8a275dc2 semaphore_wait_signal_trap + 10
1   libSystem.B.dylib             	0x00007fff8a27b40d pthread_mutex_lock + 469
2   com.apple.audio.CoreAudio     	0x00007fff857852f4 CAMutex::Lock() + 58
3   com.apple.audio.CoreAudio     	0x00007fff8579ef86 IOA_Device::StartCommandExecution(void**) + 42
4   com.apple.audio.CoreAudio     	0x00007fff857a091f HP_Device::ExecuteCommand(HP_Command*) + 75
5   com.apple.audio.CoreAudio     	0x00007fff857a5cff HP_HardwarePlugIn_DeviceStop(AudioHardwarePlugInInterface**, unsigned int, int (*)(unsigned int, AudioTimeStamp const*, AudioBufferList const*, AudioTimeStamp const*, AudioBufferList*, AudioTimeStamp const*, void*)) + 121
6   com.apple.audio.CoreAudio     	0x00007fff857a5c57 HALPlugIn::DeviceStopIOProc(HALObject const&, int (*)(unsigned int, AudioTimeStamp const*, AudioBufferList const*, AudioTimeStamp const*, AudioBufferList*, AudioTimeStamp const*, void*)) + 25
7   com.apple.audio.CoreAudio     	0x00007fff857a5bd8 AudioDeviceStop + 190
8   ...pple.audio.units.Components	0x0000000143726d1a AUGenericOutputEntry + 3062
9   ...pple.audio.units.Components	0x0000000143728d03 AUGenericOutputEntry + 11231
10  ...pple.audio.units.Components	0x000000014372b502 AUHALEntry + 3621
11  ...apple.audio.units.AudioUnit	0x00007fff89fb7d20 AudioOutputUnitStop + 38
12  libportaudio.2.dylib          	0x0000000143549ccd StopStream + 189
13  libportaudio.2.dylib          	0x000000014354546b Pa_CloseStream + 107
14  Racket                        	0x000000010028f8ac ffi_call_unix64 + 76
15  Racket                        	0x00000001002904c4 ffi_call + 644
16  Racket                        	0x000000010028289b ffi_do_call + 1371
17  Racket                        	0x000000010005d2b5 scheme_do_eval + 10917
18  Racket                        	0x000000010005fcdf _scheme_apply_from_native + 95
19  ???                           	0x00000001004d789b 0 + 4300044443
20  Racket                        	0x000000010005ce59 scheme_do_eval + 9801
21  Racket                        	0x000000010005fb2f _scheme_apply_multi_from_native + 95
22  ???                           	0x00000001004d2142 0 + 4300022082
23  Racket                        	0x000000010005ce59 scheme_do_eval + 9801
24  Racket                        	0x000000010027d458 ffi_do_callback + 520
25  Racket                        	0x00000001002907ce ffi_closure_unix64_inner + 462
26  Racket                        	0x000000010028fa2e ffi_closure_unix64 + 70
27  Racket                        	0x00000001002649f0 scheme_do_close_managed + 1024
28  Racket                        	0x00000001002669cb do_close_managed + 11
29  Racket                        	0x0000000100266b29 scheme_close_managed + 9
30  Racket                        	0x0000000100266b9f custodian_close_all + 63
31  ???                           	0x00000001004dccc5 0 + 4300065989
32  ???                           	0x00000001004dcb10 0 + 4300065552
33  ???                           	0x00000001004f6dc0 0 + 4300172736
34  ???                           	0x00000001013cb5b0 0 + 4315723184
35  ???                           	0x00000001004f9700 0 + 4300183296
36  ???                           	0x00000001053e1dfb 0 + 4382924283
37  ???                           	0x00000001004f9700 0 + 4300183296
38  ???                           	0x00000001053e1dfb 0 + 4382924283
39  ???                           	0x00000001004f9700 0 + 4300183296
40  ???                           	0x00000001004d8a50 0 + 4300048976
41  Racket                        	0x000000010005ce59 scheme_do_eval + 9801
42  Racket                        	0x00000001000771c5 scheme_dynamic_wind + 1029
43  Racket                        	0x0000000100077931 dynamic_wind + 321
44  ???                           	0x00000001004d2215 0 + 4300022293
45  ???                           	0x00000001013ccaac 0 + 4315728556
46  ???                           	0x00000001013ccaac 0 + 4315728556
47  Racket                        	0x000000010005ce59 scheme_do_eval + 9801
48  Racket                        	0x00000001000771c5 scheme_dynamic_wind + 1029
49  Racket                        	0x0000000100077931 dynamic_wind + 321
50  ???                           	0x00000001004d2215 0 + 4300022293
51  Racket                        	0x000000010005ce59 scheme_do_eval + 9801
52  Racket                        	0x0000000100078b09 scheme_finish_apply_for_prompt + 873
53  Racket                        	0x0000000100078cdc scheme_apply_for_prompt + 92
54  Racket                        	0x00000001000854d2 call_with_prompt + 1282
55  ???                           	0x00000001004d2215 0 + 4300022293
56  ???                           	0x00000001004dd0a0 0 + 4300066976
57  Racket                        	0x000000010005ce59 scheme_do_eval + 9801
58  Racket                        	0x00000001000771c5 scheme_dynamic_wind + 1029
59  Racket                        	0x0000000100077931 dynamic_wind + 321
60  ???                           	0x00000001004d2215 0 + 4300022293
61  ???                           	0x00000001013ccaac 0 + 4315728556
62  ???                           	0x00000001013ccaac 0 + 4315728556
63  Racket                        	0x000000010005ce59 scheme_do_eval + 9801
64  Racket                        	0x00000001000771c5 scheme_dynamic_wind + 1029
65  Racket                        	0x0000000100077931 dynamic_wind + 321
66  ???                           	0x00000001004d2215 0 + 4300022293
67  Racket                        	0x000000010005ce59 scheme_do_eval + 9801
68  Racket                        	0x0000000100078b09 scheme_finish_apply_for_prompt + 873
69  Racket                        	0x0000000100078cdc scheme_apply_for_prompt + 92
70  Racket                        	0x00000001000854d2 call_with_prompt + 1282
71  ???                           	0x00000001004d2215 0 + 4300022293
72  Racket                        	0x000000010005ce59 scheme_do_eval + 9801
73  Racket                        	0x000000010005fcdf _scheme_apply_from_native + 95
74  ???                           	0x00000001004d847c 0 + 4300047484
75  ???                           	0x00000001004d2282 0 + 4300022402
76  ???                           	0x00000001004d8a50 0 + 4300048976
77  ???                           	0x00000001004d8a50 0 + 4300048976
78  ???                           	0x00000001004d8a50 0 + 4300048976
79  ???                           	0x00000001004d8a50 0 + 4300048976
80  ???                           	0x00000001004d8a50 0 + 4300048976
81  ???                           	0x00000001004d8a50 0 + 4300048976
82  ???                           	0x00000001004d8a50 0 + 4300048976
83  ???                           	0x00000001004d8a50 0 + 4300048976
84  ???                           	0x00000001004d8a50 0 + 4300048976
85  ???                           	0x00000001004d8a50 0 + 4300048976
86  ???                           	0x00000001004d8a50 0 + 4300048976
87  ???                           	0x00000001004d8a50 0 + 4300048976
88  ???                           	0x00000001004d8a50 0 + 4300048976
89  ???                           	0x00000001004d8a50 0 + 4300048976
90  ???                           	0x00000001004d8a50 0 + 4300048976
91  ???                           	0x00000001004d8a50 0 + 4300048976
92  ???                           	0x00000001004d8a50 0 + 4300048976
93  ???                           	0x00000001004d8a50 0 + 4300048976
94  ???                           	0x00000001004d8a50 0 + 4300048976
95  ???                           	0x00000001004d8a50 0 + 4300048976
96  ???                           	0x00000001004d8a50 0 + 4300048976
97  ???                           	0x00000001004d8a50 0 + 4300048976
98  ???                           	0x00000001004d8a50 0 + 4300048976
99  ???                           	0x00000001004d8a50 0 + 4300048976
100 ???                           	0x00000001004d8a50 0 + 4300048976
101 ???                           	0x00000001004d8a50 0 + 4300048976
102 ???                           	0x00000001004d8a50 0 + 4300048976
103 ???                           	0x00000001004dcb10 0 + 4300065552
104 Racket                        	0x000000010005ce59 scheme_do_eval + 9801
105 Racket                        	0x0000000100078b09 scheme_finish_apply_for_prompt + 873
106 Racket                        	0x0000000100078cdc scheme_apply_for_prompt + 92
107 Racket                        	0x00000001000854d2 call_with_prompt + 1282
108 ???                           	0x00000001004d2215 0 + 4300022293
109 Racket                        	0x000000010005ce59 scheme_do_eval + 9801
110 Racket                        	0x0000000100078b09 scheme_finish_apply_for_prompt + 873
111 Racket                        	0x0000000100078cdc scheme_apply_for_prompt + 92
112 Racket                        	0x00000001000854d2 call_with_prompt + 1282
113 ???                           	0x00000001004dccc5 0 + 4300065989
114 Racket                        	0x000000010005ce59 scheme_do_eval + 9801
115 Racket                        	0x0000000100070d94 force_values + 292
116 Racket                        	0x000000010007ae72 scheme_force_value_same_mark + 114
117 ???                           	0x00000001004dc719 0 + 4300064537
118 Racket                        	0x000000010005ce59 scheme_do_eval + 9801
119 Racket                        	0x000000010005fb2f _scheme_apply_multi_from_native + 95
120 ???                           	0x00000001004d2142 0 + 4300022082
121 Racket                        	0x000000010005ce59 scheme_do_eval + 9801
122 Racket                        	0x000000010007acf3 apply_k + 179
123 Racket                        	0x000000010007b986 scheme_top_level_do_worker + 1222
124 racket                        	0x00000001000033fe finish_cmd_line_run + 3598
125 racket                        	0x0000000100004051 main_after_stack + 2753
126 Racket                        	0x000000010000d399 scheme_main_stack_setup + 153
127 racket                        	0x0000000100001da4 main + 36
128 racket                        	0x0000000100001d54 start + 52

Thread 1:
0   libSystem.B.dylib             	0x00007fff8a275d7a mach_msg_trap + 10
1   libSystem.B.dylib             	0x00007fff8a2763ed mach_msg + 59
2   Racket                        	0x0000000100292826 exception_thread + 134
3   libSystem.B.dylib             	0x00007fff8a2aefd6 _pthread_start + 331
4   libSystem.B.dylib             	0x00007fff8a2aee89 thread_start + 13

Thread 2:
0   libSystem.B.dylib             	0x00007fff8a2d799e __sigwait + 10
1   libSystem.B.dylib             	0x00007fff8a2d7977 sigwait + 73
2   Racket                        	0x00000001001a4511 mz_proc_thread_signal_worker + 161
3   Racket                        	0x00000001001613b0 mzrt_thread_stub + 96
4   libSystem.B.dylib             	0x00007fff8a2aefd6 _pthread_start + 331
5   libSystem.B.dylib             	0x00007fff8a2aee89 thread_start + 13

Thread 3:
0   libSystem.B.dylib             	0x00007fff8a2b0a6a __semwait_signal + 10
1   libSystem.B.dylib             	0x00007fff8a2b4881 _pthread_cond_wait + 1286
2   Racket                        	0x00000001001aa294 green_thread_timer + 148
3   Racket                        	0x00000001001613b0 mzrt_thread_stub + 96
4   libSystem.B.dylib             	0x00007fff8a2aefd6 _pthread_start + 331
5   libSystem.B.dylib             	0x00007fff8a2aee89 thread_start + 13

Thread 4:  Dispatch queue: com.apple.libdispatch-manager
0   libSystem.B.dylib             	0x00007fff8a28ec0a kevent + 10
1   libSystem.B.dylib             	0x00007fff8a290add _dispatch_mgr_invoke + 154
2   libSystem.B.dylib             	0x00007fff8a2907b4 _dispatch_queue_invoke + 185
3   libSystem.B.dylib             	0x00007fff8a2902de _dispatch_worker_thread2 + 252
4   libSystem.B.dylib             	0x00007fff8a28fc08 _pthread_wqthread + 353
5   libSystem.B.dylib             	0x00007fff8a28faa5 start_wqthread + 13

Thread 5:  com.apple.CFSocket.private
0   libSystem.B.dylib             	0x00007fff8a2b9932 select$DARWIN_EXTSN + 10
1   com.apple.CoreFoundation      	0x00007fff81482498 __CFSocketManager + 824
2   libSystem.B.dylib             	0x00007fff8a2aefd6 _pthread_start + 331
3   libSystem.B.dylib             	0x00007fff8a2aee89 thread_start + 13

Thread 6:
0   libSystem.B.dylib             	0x00007fff8a2b9932 select$DARWIN_EXTSN + 10
1   Racket                        	0x00000001001b9166 default_sleep + 294
2   Racket                        	0x0000000100258a6b check_sleep + 1371
3   Racket                        	0x0000000100263511 scheme_thread_block + 2241
4   Racket                        	0x0000000100263bfc scheme_block_until + 332
5   Racket                        	0x00000001002653f5 do_sync + 1173
6   ???                           	0x00000001004d2215 0 + 4300022293
7   Racket                        	0x000000010005ce59 scheme_do_eval + 9801
8   Racket                        	0x000000010005fb2f _scheme_apply_multi_from_native + 95
9   ???                           	0x00000001004d2142 0 + 4300022082
10  Racket                        	0x000000010005ce59 scheme_do_eval + 9801
11  Racket                        	0x000000010007acf3 apply_k + 179
12  Racket                        	0x000000010007b986 scheme_top_level_do_worker + 1222
13  Racket                        	0x00000001001a9b4d place_start_proc_after_stack + 1373
14  Racket                        	0x00000001001a9bc4 place_start_proc + 100
15  Racket                        	0x00000001001613b0 mzrt_thread_stub + 96
16  libSystem.B.dylib             	0x00007fff8a2aefd6 _pthread_start + 331
17  libSystem.B.dylib             	0x00007fff8a2aee89 thread_start + 13

Thread 7:
0   libSystem.B.dylib             	0x00007fff8a2b0a6a __semwait_signal + 10
1   libSystem.B.dylib             	0x00007fff8a2b4881 _pthread_cond_wait + 1286
2   Racket                        	0x00000001001aa294 green_thread_timer + 148
3   Racket                        	0x00000001001613b0 mzrt_thread_stub + 96
4   libSystem.B.dylib             	0x00007fff8a2aefd6 _pthread_start + 331
5   libSystem.B.dylib             	0x00007fff8a2aee89 thread_start + 13

Thread 8:
0   libSystem.B.dylib             	0x00007fff8a2b0a6a __semwait_signal + 10
1   libSystem.B.dylib             	0x00007fff8a2b4881 _pthread_cond_wait + 1286
2   Racket                        	0x00000001001aa08b pt_sema_wait + 43
3   Racket                        	0x00000001001aa0cc do_watch + 28
4   libSystem.B.dylib             	0x00007fff8a2aefd6 _pthread_start + 331
5   libSystem.B.dylib             	0x00007fff8a2aee89 thread_start + 13

Thread 9:
0   libSystem.B.dylib             	0x00007fff8a275d7a mach_msg_trap + 10
1   libSystem.B.dylib             	0x00007fff8a2763ed mach_msg + 59
2   com.apple.CoreFoundation      	0x00007fff81460932 __CFRunLoopRun + 1698
3   com.apple.CoreFoundation      	0x00007fff8145fdbf CFRunLoopRunSpecific + 575
4   com.apple.audio.CoreAudio     	0x00007fff857b5786 HALRunLoop::OwnThread(void*) + 152
5   com.apple.audio.CoreAudio     	0x00007fff857a2755 CAPThread::Entry(CAPThread*) + 125
6   libSystem.B.dylib             	0x00007fff8a2aefd6 _pthread_start + 331
7   libSystem.B.dylib             	0x00007fff8a2aee89 thread_start + 13

Thread 10:
0   libSystem.B.dylib             	0x00007fff8a2b0a6a __semwait_signal + 10
1   libSystem.B.dylib             	0x00007fff8a2b4881 _pthread_cond_wait + 1286
2   Racket                        	0x0000000100160d0b mzrt_sema_wait + 59
3   Racket                        	0x000000010027d59f ffi_queue_callback + 175
4   Racket                        	0x00000001002907ce ffi_closure_unix64_inner + 462
5   Racket                        	0x000000010028fa2e ffi_closure_unix64 + 70
6   libportaudio.2.dylib          	0x00000001435469d0 AdaptingOutputOnlyProcess + 224
7   libportaudio.2.dylib          	0x0000000143547398 PaUtil_EndBufferProcessing + 552
8   libportaudio.2.dylib          	0x000000014354c3a7 AudioIOProc + 2295
9   ...pple.audio.units.Components	0x000000014372517a 0x14371d000 + 33146
10  ...pple.audio.units.Components	0x000000014372480e 0x14371d000 + 30734
11  ...pple.audio.units.Components	0x0000000143723323 0x14371d000 + 25379
12  ...pple.audio.units.Components	0x000000014372245c 0x14371d000 + 21596
13  ...pple.audio.units.Components	0x0000000143727fd0 AUGenericOutputEntry + 7852
14  com.apple.audio.CoreAudio     	0x00007fff857a533d HP_IOProc::Call(AudioTimeStamp const&, AudioTimeStamp const&, AudioBufferList const*, AudioTimeStamp const&, AudioBufferList*) + 313
15  com.apple.audio.CoreAudio     	0x00007fff857a510f IOA_Device::CallIOProcs(AudioTimeStamp const&, AudioTimeStamp const&, AudioTimeStamp const&) + 303
16  com.apple.audio.CoreAudio     	0x00007fff857a4f45 HP_IOThread::PerformIO(AudioTimeStamp const&, double) + 771
17  com.apple.audio.CoreAudio     	0x00007fff857a2f54 HP_IOThread::WorkLoop() + 1832
18  com.apple.audio.CoreAudio     	0x00007fff857a2827 HP_IOThread::ThreadEntry(HP_IOThread*) + 9
19  com.apple.audio.CoreAudio     	0x00007fff857a2755 CAPThread::Entry(CAPThread*) + 125
20  libSystem.B.dylib             	0x00007fff8a2aefd6 _pthread_start + 331
21  libSystem.B.dylib             	0x00007fff8a2aee89 thread_start + 13


-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4624 bytes
Desc: not available
URL: <http://lists.racket-lang.org/users/archive/attachments/20110910/6cebeaae/attachment.p7s>

Posted on the users mailing list.