TSAN and pthread_setcancelstate()

Hi all,

I hope this is the right list for my question. If not, please accept
my apologies -- in that case I would also appreciate if you could tell
me the right place to ask.

I am using TSAN together with clang (3,4,5) on Linux (in this Case
Ubuntu 16.04). It works great, but I always get race reports (sample
after my sig) on pthread_setcancelstate(). The POSIX doc states that
it sets the cancellation state for the *current thread* so there
should be no cross-thread data races. To validate this, I have also
checked the GNU libc and pthread implemenation and the both access
thread-local storage.

So I wonder what I may be doing wrong and most importantly what I can
decently do in order to get rid of the TSAN message (false positive?).
I know I can disable TSAN on a function basis, but that is a but
clumpsy as I do not want to disable if for more but the
pthread_setcancelstate. In an extreme, I probably need to move it to
an inline wrapper, but I don't consider this to be really clean.

Any advise, especially on the root cause, would be much appreciated.
It makes me kind of nervous not understanding why this happens at

Thanks in advance,

Sample Report:
WARNING: ThreadSanitizer: data race (pid=103016)
  Write of size 1 at 0x7c0000000000 by main thread:
    #0 pthread_setcancelstate <null> (rsyslogd+0x00000043a830)
    #1 qqueueEnqMsg /home/rger/proj/rsyslog/runtime/queue.c:3039:3
    #2 submitMsg2 /home/rger/proj/rsyslog/tools/rsyslogd.c:1015:2
    #3 logmsgInternal_doWrite
    #4 processImInternal
    #5 mainloop /home/rger/proj/rsyslog/tools/rsyslogd.c:1787:3
    #6 main /home/rger/proj/rsyslog/tools/rsyslogd.c:1965:2

  Previous write of size 1 at 0x7c0000000000 by thread T1:
    #0 pthread_setcancelstate <null> (rsyslogd+0x00000043a830)
    #1 ConsumerReg /home/rger/proj/rsyslog/runtime/queue.c:2029:2
    #2 wtiWorker /home/rger/proj/rsyslog/runtime/wti.c:366:14
    #3 wtpWorker /home/rger/proj/rsyslog/runtime/wtp.c:415:2

  Thread T1 'rs:main Q[DA]:R' (tid=103049, running) created by main thread at:
    #0 pthread_create <null> (rsyslogd+0x00000042dc76)
    #1 wtpStartWrkr /home/rger/proj/rsyslog/runtime/wtp.c:464:11
    #2 wtpAdviseMaxWorkers /home/rger/proj/rsyslog/runtime/wtp.c:520:4
    #3 qqueueAdviseMaxWorkers
    #4 qqueueStart /home/rger/proj/rsyslog/runtime/queue.c:2437:2
    #5 StartDA /home/rger/proj/rsyslog/runtime/queue.c:450:9
    #6 InitDA /home/rger/proj/rsyslog/runtime/queue.c:514:3
    #7 qqueueStart /home/rger/proj/rsyslog/runtime/queue.c:2430:3
    #8 startMainQueue /home/rger/proj/rsyslog/tools/rsyslogd.c:829:2
    #9 activateMainQueue
    #10 activate /home/rger/proj/rsyslog/runtime/rsconf.c:883:2
    #11 initAll /home/rger/proj/rsyslog/tools/rsyslogd.c:1507:2
    #12 main /home/rger/proj/rsyslog/tools/rsyslogd.c:1957:2

SUMMARY: ThreadSanitizer: data race
(/home/rger/proj/rsyslog/tools/rsyslogd+0x43a830) in

Adding to my own question:

I have tried to use __attribute__((no_sanitize("thread"))) and
blacklisting to work around the issue, but without any success.

Details in commit

This has now actually become a blocker for me in regard to adoption of
TSAN. Any help would be highly appreciated!

Thanks and happy new year,