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

hpx::promise has some problems #1740

Closed
dmarce1 opened this issue Sep 2, 2015 · 1 comment
Closed

hpx::promise has some problems #1740

dmarce1 opened this issue Sep 2, 2015 · 1 comment

Comments

@dmarce1
Copy link
Member

dmarce1 commented Sep 2, 2015

I've having problems with my code that disappear when I change the implementation of the "channel" class I am using from using a promise/future pair to using a semaphore. When using the promise/future implementation, I get unexpected hangs, crashes, and other problems, but when I use the semaphore implementation, these problems go away (the code still hangs during output and at startup sometimes but I think that is a different issue). The promise/future implementation of the channel class is here:
https://github.com/dmarce1/FVFMM/blob/master/src/channel.hpp

and the new implementation that seems to get rid of problems is

#ifndef CHANNEL_HPP_
#define CHANNEL_HPP_

#include "defs.hpp"

template<class T>
class channel {
private:
    hpx::lcos::local::counting_semaphore signal;
    T data;
    std::atomic<bool> full;
public:
    channel() : full(false){
    }
    ~channel() = default;
    channel(const channel&) = delete;
    channel(channel&& other ) = delete;
    channel& operator=(channel&& other ) = delete;

    template<class U>
    void set_value( U value ) {
        assert(!full);
        data = std::move(value);
        full = true;
        signal.signal();
    }

    T get() {
        signal.wait();
        assert(full);
        full = false;
        return data;
    }

};


#endif /* CHANNEL_HPP_ */

Using the promise/future implementation seems to have also called problems for other calls to the future class functions, even on futures not produced from a promise. For instance, calls to future::wait_for and future::wait_until would act weird, issuing timeouts as if the timing had started when the program was initiated rather than when wait_for/until was called - and for futures not created with a promise. These problems disappeared when I changed channel implementations.

I will try and reproduce the problem with a smaller code.

@dmarce1
Copy link
Member Author

dmarce1 commented Sep 16, 2015

I think I was wrong on this one. I get hangs and crashes even with the semaphore version of my channel, and the trap I had written to detect if the promise/future channel had a bug in it, itself, had a bug. I've also determined the problem with wait_for occurs even in a simple test code.

@dmarce1 dmarce1 closed this as completed Sep 16, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants