Add mutex round static member used in a thread
ClosedPublic

Authored by davidedmundson on Mar 23 2018, 2:12 AM.

Details

Summary

BackgroundFinder runs in a separate thread, it uses a static QStringList cache
It's perfectly plausible that two BackgroundFinders threads could run at once

Test Plan

Old code didn't crash, it was a pure hypothetical.
Works as before

Diff Detail

Repository
R120 Plasma Workspace
Branch
master
Lint
No Linters Available
Unit
No Unit Test Coverage
davidedmundson created this revision.Mar 23 2018, 2:12 AM
Restricted Application added a project: Plasma. · View Herald TranscriptMar 23 2018, 2:12 AM
Restricted Application added a subscriber: plasma-devel. · View Herald Transcript
davidedmundson requested review of this revision.Mar 23 2018, 2:12 AM
anthonyfieroni added inline comments.
wallpapers/image/backgroundlistmodel.cpp
532

Potentially it still can produce a crash, the function returns a reference to list, simultaneously read/write on list is race condition. So function can return a copy to static list for this function, then global variables or mutexes doesn't needed.

Very well spotted!

In this specific case it's probably fine as it's never modified after construction, but I'll change anyway.

shallow-copy QStringList outside mutex

mart accepted this revision.Mar 23 2018, 12:56 PM
This revision is now accepted and ready to land.Mar 23 2018, 12:56 PM
This revision was automatically updated to reflect the committed changes.