Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multithreading #4

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

tyleretzel
Copy link
Contributor

  • Multiple mixers now run concurrently
  • Mixer sends allocations made by a producer to be freed by other threads

- mixer selects which producers to run
- two different producers with different allocation patterns
Copy link
Member

@davidtgoldblatt davidtgoldblatt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly looks good; just some C++ style things.

producers.push_back(std::move(std::make_unique<VectorProducer>(
100000, std::chrono::duration<double>(1.0))));
// Initialize producers
vector<shared_ptr<Producer>> producers;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the change to shared_ptr? I'd expect this to be a unique_ptr.

Copy link
Contributor Author

@tyleretzel tyleretzel Jun 13, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this iteration, the producers were basically immutable configuration objects, and each mixer ran the same set of producers, so it made sense to share producers. I've since changed this back to unique because these assumptions are no longer true.

vector<std::thread> threads;
vector<shared_ptr<ToFreeQueue>> toFreeQueues;
for (int i = 0; i < FLAGS_num_threads; i++) {
shared_ptr<ToFreeQueue> toFreeQ = make_shared<ToFreeQueue>();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usually in a situation like this, you'd say auto toFreeQ = make_shared<ToFreeQueue>();; the idea being that you only say the type once.

(Some people go even further, and put auto wherever they can).

high_resolution_clock::time_point beginTime = high_resolution_clock::now();
m.run();
for (auto it = begin(threads); it != end(threads); ++it) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More idiomatically:

for (auto& thread : threads) {


// Picks next producer for the mixer to run. Currently uniform random choice
const Producer &Mixer::pick() {
int producerIndex = this->producerIndexPicker_(this->generator_);
const Producer &Mixer::pickProducer() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More idiomatic is for the & to go on the left (I know this isn't jemalloc "core" style, but it's more idiomatic in C++).

- Mixer creates producer consumer relations: picks a random producer,
and then a random consumer to free the memory allocated in the producer.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants