Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Executing pthread "pre init" function on thread start

Tags:

c

linux

pthreads

I am using an external linux library that starts pthreads.

Is there any way I can setup a trigger that calls a supplied function when a new pthread starts from the context of the thread before the threads "main" function starts? (Like installing a signal handler or whatever)

like image 621
Andrew Tomazos Avatar asked Dec 22 '25 00:12

Andrew Tomazos


1 Answers

There is no standard API that does what you have asked for. There are always complex and fragile alternatives; For example, you can build a filter Shared Lib (see the option --filter=name in the man page for ld) to intercept pthread_create, and make your own wrapper function around the callers actual function for the thread.

like image 137
bmargulies Avatar answered Dec 23 '25 14:12

bmargulies