Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TSAN] Data race on the consumer position property #435

Open
alcinos opened this issue Apr 27, 2019 · 5 comments

Comments

Projects
None yet
3 participants
@alcinos
Copy link
Contributor

commented Apr 27, 2019

Nothing prevents querying the consumer position while it's being read in the video player

WARNING: ThreadSanitizer: data race (pid=5539)
  Write of size 4 at 0x7b4c000754f0 by thread T32:
    #0 on_consumer_frame_show /home/nicolas/Documents/Developpement/Projets/mlt/src/framework/mlt_consumer.c:376 (libmlt.so.6+0x31ad1)
    #1 mlt_consumer_frame_show /home/nicolas/Documents/Developpement/Projets/mlt/src/framework/mlt_consumer.c:343 (libmlt.so.6+0x31a0d)
    #2 mlt_events_fire /home/nicolas/Documents/Developpement/Projets/mlt/src/framework/mlt_events.c:216 (libmlt.so.6+0x20ec3)
    #3 consumer_play_video /home/nicolas/Documents/Developpement/Projets/mlt/src/modules/sdl2/consumer_sdl2.c:686 (libmltsdl2.so+0x692d)
    #4 video_thread /home/nicolas/Documents/Developpement/Projets/mlt/src/modules/sdl2/consumer_sdl2.c:767 (libmltsdl2.so+0x6e10)

  Previous read of size 4 at 0x7b4c000754f0 by main thread:
    #0 mlt_consumer_position /home/nicolas/Documents/Developpement/Projets/mlt/src/framework/mlt_consumer.c:1755 (libmlt.so.6+0x35ca5)
    #1 transport /home/nicolas/Documents/Developpement/Projets/mlt/src/melt/melt.c:465 (melt+0x5147)
    #2 main /home/nicolas/Documents/Developpement/Projets/mlt/src/melt/melt.c:1004 (melt+0x70a2)

  Location is heap block of size 400 at 0x7b4c00075400 allocated by main thread:
    #0 calloc /build/gcc/src/gcc/libsanitizer/tsan/tsan_interceptors.cc:623 (libtsan.so.0+0x2b144)
    #1 calloc /build/gcc/src/gcc/libsanitizer/tsan/tsan_interceptors.cc:618 (libtsan.so.0+0x2b144)
    #2 mlt_consumer_init /home/nicolas/Documents/Developpement/Projets/mlt/src/framework/mlt_consumer.c:109 (libmlt.so.6+0x30d21)
    #3 consumer_sdl2_init /home/nicolas/Documents/Developpement/Projets/mlt/src/modules/sdl2/consumer_sdl2.c:99 (libmltsdl2.so+0x3b55)
    #4 mlt_repository_create /home/nicolas/Documents/Developpement/Projets/mlt/src/framework/mlt_repository.c:245 (libmlt.so.6+0x3bcda)
    #5 mlt_factory_consumer /home/nicolas/Documents/Developpement/Projets/mlt/src/framework/mlt_factory.c:435 (libmlt.so.6+0x3b297)
    #6 create_consumer /home/nicolas/Documents/Developpement/Projets/mlt/src/melt/melt.c:271 (melt+0x4438)
    #7 main /home/nicolas/Documents/Developpement/Projets/mlt/src/melt/melt.c:920 (melt+0x6adb)

  Thread T32 (tid=5573, running) created by thread T12 at:
    #0 pthread_create /build/gcc/src/gcc/libsanitizer/tsan/tsan_interceptors.cc:915 (libtsan.so.0+0x2bf03)
    #1 consumer_thread /home/nicolas/Documents/Developpement/Projets/mlt/src/modules/sdl2/consumer_sdl2.c:838 (libmltsdl2.so+0x711c)

SUMMARY: ThreadSanitizer: data race /home/nicolas/Documents/Developpement/Projets/mlt/src/framework/mlt_consumer.c:376 in on_consumer_frame_show
@ddennedy

This comment has been minimized.

Copy link
Member

commented Apr 27, 2019

Besides the tool reporting something, what is the actual problem?

@alcinos

This comment has been minimized.

Copy link
Contributor Author

commented Apr 27, 2019

We are getting weird bugs/crashes in Kdenlive, and at this point I strongly suspect a data race of some form. Hence I'm trying to catalog and possibly fix the ones I can find. Besides, even benign looking races can go really wrong: see for eg https://software.intel.com/en-us/blogs/2013/01/06/benign-data-races-what-could-possibly-go-wrong

@ddennedy

This comment has been minimized.

Copy link
Member

commented Apr 27, 2019

I just want to understand more about the problem instead of react to the tool. For example, it seems like setting an integer (position member) is a single instruction, and reading it is another instruction on another thread. Is a int write not atomic such that only some of the bytes are written before it is read? I skimmed the article, and it looks interesting; I will read more.

@bmatherly

This comment has been minimized.

Copy link
Member

commented Apr 28, 2019

I can confirm that there is still danger even with simple integer read/write operations. For example, on thread on one NUMA node could update an integer. That would cause the cache on the NUMA node to be updated, but it may not be flushed to main memory yet. Another thread on another NUMA node could read the same variable and get the wrong value. std::atomic is designed to solve that problem without the use of heavy thread synchronization methods:
https://en.cppreference.com/w/cpp/atomic/atomic

@alcinos

This comment has been minimized.

Copy link
Contributor Author

commented Apr 29, 2019

std::atomic is c++, but there seem to have a C11 version of it https://en.cppreference.com/w/c/atomic
That being said, all threading primitives are much nicely exposed in c++.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.