This is an archive of the discontinued LLVM Phabricator instance.

Thread safety analysis: Improve documentation for scoped capabilities
ClosedPublic

Authored by aaronpuchert on Sep 2 2020, 6:02 PM.

Details

Summary

They are for more powerful than the current documentation implies, this
adds

  • adopting a lock,
  • deferring a lock,
  • manually unlocking the scoped capability,
  • relocking the scoped capability, possibly in a different mode,
  • try-relocking the scoped capability.

Also there is now a generic explanation how attributes on scoped
capabilities work. There has been confusion in the past about how to
annotate them (see e.g. PR33504), hopefully this clears things up.

Diff Detail

Event Timeline

aaronpuchert created this revision.Sep 2 2020, 6:02 PM
Herald added a project: Restricted Project. · View Herald TranscriptSep 2 2020, 6:02 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
aaronpuchert requested review of this revision.Sep 2 2020, 6:02 PM

Not sure about the added comments, I can also remove them if they're not helpful.

@aaron.ballman, this addresses your earlier comment D81332#2079489.

aaron.ballman added inline comments.Sep 3 2020, 6:52 AM
clang/docs/ThreadSafetyAnalysis.rst
928

This makes it sound like we're missing a diagnostic, but IIRC, this is intended behavior. Maybe we want to say there is purposefully no warning on double unlock and why? Or add a FIXME if I'm remembering wrong and this isn't intended behavior.

aaronpuchert added inline comments.Sep 3 2020, 9:25 AM
clang/docs/ThreadSafetyAnalysis.rst
914

s/t_mutex/Mutex/g

928

It is intentional (we have special handling for the destructor), and I also think it makes sense. I just wanted to clarify the difference between this and Unlock: calling Unlock twice is not allowed, but calling Unlock and then (implicitly) the destructor is allowed.

I could rephrase this as "There is no warning if the scope was already unlocked before." Could also add an "intentional" or "deliberate", but since it's documented I think the reader can infer that.

aaronpuchert marked an inline comment as done.
  • More detailed description how scoped capabilities work.
  • Make the comment wording more consistent with existing comments and the previous explanation.
  • Properly implement the destructor in the presence of an Unlock() function: we need to keep track of the status then.
  • Add try-acquire functions on scoped lock.
  • Fix compiler errors.
aaronpuchert edited the summary of this revision. (Show Details)Sep 3 2020, 3:44 PM
aaron.ballman accepted this revision.Sep 4 2020, 6:28 AM

Ah, this reads more clearly to me, thank you for the additional changes. LGTM!

This revision is now accepted and ready to land.Sep 4 2020, 6:28 AM