Skip to content

Commit

Permalink
Restored exercise2 to original form
Browse files Browse the repository at this point in the history
  • Loading branch information
shuhaowu committed Oct 10, 2023
1 parent 51042e5 commit c5fecad
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,20 @@
struct SingleData {
// Exercise2-1: Remove the lock from this function
void Set(const double value) {
std::scoped_lock lock(mutex_);
value_ = value;
}

// Exercise2-1: Remove the lock from this function
double Get() {
std::scoped_lock lock(mutex_);
return value_;
}

private:
// Exercise2-1: Remove the lock and replace the double with a std::atomic<double>
static_assert(std::atomic<double>::is_always_lock_free);
std::atomic<double> value_;
std::mutex mutex_;
double value_;
};

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ struct MultipleData {
private:
// Exercise 2-2: Change this mutex to a priority inheritance mutex
// A priority inheritance mutex implementation is available as cactus_rt::mutex
using mutex = cactus_rt::mutex;
using mutex = std::mutex;
mutex pid_constant_mutex_;

PIDConstants pid_constants_;
Expand Down

0 comments on commit c5fecad

Please sign in to comment.