« FileMaker Testing on … | Home | LDAP in FileMaker »

Thread Names


Today I want to introduce you to SetThreadNameMBS, a newer function you can use in our MBS Xojo and Real Studio Plugins (15.5pr2).

Our plugin calls the SetThreadName function already for all the preemptive threads like for CURL or SQL. In a crash report you see the thread name and you can identify what the thread does. For example we create a project in Xojo and run there two threads. We name the main thread, the first and second test thread. Now we let one thread crash with a NULL pointer easily. In the crash report we can now see which thread is doing what by seeing our names:

Thread 0:: This is my Main Thread Dispatch queue: com.apple.main-thread
0 libsystem_kernel.dylib 0x96d9c9ce mach_msg_trap + 10
1 libsystem_kernel.dylib 0x96d9ba70 mach_msg + 68
2 com.apple.CoreServices.CarbonCore 0x9a9d7f6a YieldToThread + 429
3 rbframework.dylib 0x001f6791 0x1d4000 + 141201
4 rbframework.dylib 0x001f7388 threadRun + 392
...

Thread 10:
0 libsystem_kernel.dylib 0x96da2e6a __workq_kernreturn + 10
1 libsystem_pthread.dylib 0x9963372a _pthread_wqthread + 939
2 libsystem_pthread.dylib 0x99630e0e start_wqthread + 30

Thread 11:: TestThread
0 libsystem_kernel.dylib 0x96d9c9ce mach_msg_trap + 10
1 libsystem_kernel.dylib 0x96d9ba70 mach_msg + 68
2 com.apple.CoreServices.CarbonCore 0x9a9d7f6a YieldToThread + 429
3 rbframework.dylib 0x001f6791 0x1d4000 + 141201
4 rbframework.dylib 0x00277684 0x1d4000 + 669316
5 rbframework.dylib 0x0027135f RuntimeBackgroundTask + 47
6 0x00170c14 MainWindow.MainWindow.Thread1_Run%%oo + 96
7 0x001739ff Delegate.IM_Invoke%%o + 110
8 0x00173a40 AddHandler.Stub.0%% + 51
9 rbframework.dylib 0x001f7450 0x1d4000 + 144464
10 com.apple.CoreServices.CarbonCore 0x9a9d7b88 CooperativeThread + 305
11 libsystem_pthread.dylib 0x99633c25 _pthread_body + 138
12 libsystem_pthread.dylib 0x99633b9b _pthread_start + 162
13 libsystem_pthread.dylib 0x99630e32 thread_start + 34

Thread 12 Crashed:: CrashingTestThread
0 0x00170d11 MainWindow.MainWindow.Thread2_Run%%oo + 117
1 0x001739ff Delegate.IM_Invoke%%o + 110
2 0x00173a40 AddHandler.Stub.0%% + 51
3 rbframework.dylib 0x001f7450 0x1d4000 + 144464
4 com.apple.CoreServices.CarbonCore 0x9a9d7b88 CooperativeThread + 305
5 libsystem_pthread.dylib 0x99633c25 _pthread_body + 138
6 libsystem_pthread.dylib 0x99633b9b _pthread_start + 162
7 libsystem_pthread.dylib 0x99630e32 thread_start + 34

The thread with number 10 is created by OS X and has no name. Out threads with indexes 0, 11 and 12 have names.
This does help debugging, because we often have several things running and just one instance crashes. The thread name allows us to pass a text value to the crash report. This can be the ID of a transaction, the name of the PDF we process or the file we upload. We may have ten threads with same code run in different instances, but the thread name in the crash report may give us the clue we need to find the problem.

Should work fine on OS X, Windows and Linux. Please try it.
13 12 15 - 17:17
three comments

Very nice! :-)
Markus Winter - 14 12 15 - 21:19

Woohoo! :)
Amando - 15 12 15 - 02:01

This is gonna be helpful!
Dan - 17 12 15 - 17:52


  
Remember personal info?

Emoticons / Textile


Notify:
Hide email:

Small print: All html tags except <b> and <i> will be removed from your comment. You can make links by just typing the url or mail-address.