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

Fixing problems as reported by clang-check. #1889

Merged
merged 3 commits into from Dec 18, 2015
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
34 changes: 10 additions & 24 deletions examples/balancing/hpx_thread_phase.cpp
Expand Up @@ -38,14 +38,15 @@ using hpx::threads::set_thread_state;
using hpx::init;
using hpx::finalize;

typedef queue<std::pair<thread_id_type, std::size_t>*> fifo_type;
typedef std::pair<thread_id_type, std::size_t> value_type;
typedef std::vector<value_type> fifo_type;

///////////////////////////////////////////////////////////////////////////////
void lock_and_wait(
mutex& m
, barrier& b0
, barrier& b1
, fifo_type& hpxthreads
, value_type& entry
, std::size_t wait
) {
// Wait for all hpxthreads in this iteration to be created.
Expand All @@ -60,8 +61,7 @@ void lock_and_wait(

if (l.owns_lock())
{
hpxthreads.push(new std::pair<thread_id_type, std::size_t>
(this_, get_thread_phase(this_)));
entry = value_type(this_, get_thread_phase(this_));
break;
}

Expand Down Expand Up @@ -106,23 +106,20 @@ int hpx_main(variables_map& vm)
// Have the fifo preallocate storage.
fifo_type hpxthreads(hpxthread_count);

std::vector<mutex*> m(mutex_count, 0);
barrier b0(hpxthread_count + 1), b1(hpxthread_count + 1);

// Allocate the mutexes.
for (std::size_t j = 0; j < mutex_count; ++j)
m[j] = new mutex;
std::vector<mutex> m(mutex_count);
barrier b0(hpxthread_count + 1), b1(hpxthread_count + 1);

for (std::size_t j = 0; j < hpxthread_count; ++j)
{
// Compute the mutex to be used for this thread.
const std::size_t index = j % mutex_count;

register_thread(boost::bind
(&lock_and_wait, boost::ref(*m[index])
(&lock_and_wait, boost::ref(m[index])
, boost::ref(b0)
, boost::ref(b1)
, boost::ref(hpxthreads)
, boost::ref(hpxthreads[j])
, wait)
, "lock_and_wait");
}
Expand All @@ -134,22 +131,11 @@ int hpx_main(variables_map& vm)
b1.wait();

// {{{ Print results for this iteration.
std::pair<thread_id_type, std::size_t>* entry = 0;

while (hpxthreads.pop(entry))
for(value_type &entry: hpxthreads)
{
HPX_ASSERT(entry);
std::cout << " " << entry->first << "," << entry->second << "\n";
delete entry;
std::cout << " " << entry.first << "," << entry.second << "\n";
}
// }}}

// Destroy the mutexes.
for (std::size_t j = 0; j < mutex_count; ++j)
{
HPX_ASSERT(m[j]);
delete m[j];
}
}

// Initiate shutdown of the runtime system.
Expand Down