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

phmap::parallel_flat_hash_map<uint32_t, uint32_t> erase_if crash? #263

Open
aengusjiang opened this issue Dec 14, 2024 · 4 comments
Open

Comments

@aengusjiang
Copy link

aengusjiang commented Dec 14, 2024

phmap::parallel_flat_hash_map<uint32_t, uint32_t> erase crash?

class waiter final : sig_event
{
public:
static waiter& inst();
~waiter() override;

bool stop() const;
void on_signal(int sig) override;

void add(uint32_t num = 1, uint16_t theme = 0);
bool wait(uint16_t theme = 0, uint32_t timeout = 0, bool quite = true) const;
void done(uint16_t theme = 0);
uint32_t to_do(uint16_t theme = 0) const;

private:
static void atexit_cb();
waiter();

using parallel_wait_map = phmap::parallel_flat_hash_map<uint32_t, uint32_t>;

//////////////////////////////////////////////////////////////////////////
bool m_stop{ false };
parallel_wait_map m_wait_map;

};

image

multi thread call stack:
image

@aengusjiang aengusjiang changed the title phmap::parallel_flat_hash_map<uint32_t, uint32_t> erase crash? phmap::parallel_flat_hash_map<uint32_t, uint32_t> erase_if crash? Dec 14, 2024
@greg7mdp
Copy link
Owner

greg7mdp commented Dec 14, 2024

This is not really a crash, it hits an assert. Most likely is it not a bug in phmap, but an incorrect use.
Please send me a small example I can build that reproduces the issue, and I'll look into it.

@aengusjiang
Copy link
Author

Hi greg7mdp. Thanks for your support.
It really is caused by my incorrect use.
I found that, the parallel map default use class Mutex = phmap::NullMutex in phmap_fwd_decl.h:111,
so it is not mutex read/write and cause the crash.

@aengusjiang
Copy link
Author

Is it better use class Mutex = std::mutex by default for parallel_xxx container?

@greg7mdp
Copy link
Owner

Yes, I would suggest using std::mutex by default.

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

No branches or pull requests

2 participants