Kaldaien / TZF

Tales of Zestiria "Fix" - Framerate, Render and Sound Fixes
GNU General Public License v2.0
115 stars 15 forks source link

std::unordered_map::operator[] is not thread safe #4

Closed PeterTh closed 8 years ago

PeterTh commented 8 years ago

I doubt it occurs often in practice, but in principle lines like https://github.com/Kaldaien/TZF/blob/4c026b318a489294d5aecc8afba94eab4261f12d/tzf_dsound/framerate.cpp#L154 called from arbitrary threads are a race condition per the standard.

Kaldaien commented 8 years ago

Thank you for pointing this out. I was trying an alternative to thread-local-storage because that doesn't work right in DLLs on all versions of Windows. I'll definitely look into this.

PeterTh commented 8 years ago

Well, the simplest solution would be to mutex the write accesses and change the reads to find.

Kaldaien commented 8 years ago

The logic that was storing per-thread timing turns out not to be necessary as long as I limit the interest to the thread that is using the D3D9 swapchain. DrDaxxy has isolated the exact conditional jump that needs to be bypassed and this code becomes obsolete.

PeterTh commented 8 years ago

Well, that's even better. Code that doesn't exist can't fail ;)