what is impact if i call syscall(SYS_gettid) from signal Handler?

1.3k views Asked by At

Can some one tell me what could be the adverse effect of calling syscall(SYS_gettid) from Signal Handler? I know it is not in the safe functions list to be called from signal handler but I want to know reason behind it?

1

There are 1 answers

0
TinyTimZamboni On BEST ANSWER

I'm pretty sure this has to do with the Signal Handler methods being reentrant. Suppose a signal is sent, and your handler grabs the signal and starts processing. While processing, another signal may be sent by a concurrent program, and your handler again grabs that signal, and starts processing it.

Depending on how the scheduling works out, it's possible that the same chunk of code, the Signal Handler, executes during its own execution. The problem is that it uses the same pointers and variables, so it can corrupt itself, especially because gettid() returns the ID of the current thread. Which is the current thread in this case?