arvidn / libtorrent

an efficient feature complete C++ bittorrent implementation

Home Page:http://libtorrent.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

libtorrent::aux::watermark_callback thread-safety issue

dushabaev opened this issue · comments

Here is a libtorrent::aux::watermark_callback::watermark_callback() function. It's called only on the network thread, so this function itself is ok.

Now, let's look at how it's posted: disk_buffer_pool.cpp#L106.

The post() function itself should be thread-safe, so unlocking passed lock l before posting seems okay too.

But if check_buffer_level would be called simultaneously with watermark_callback, then this swap() corrupts watermark_callback's loop over cbs

Should we consider pass lock inside watermark_callback too?