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

Synchronization problem. #6

Closed
khrynczenko opened this issue Apr 1, 2018 · 1 comment
Closed

Synchronization problem. #6

khrynczenko opened this issue Apr 1, 2018 · 1 comment

Comments

@khrynczenko
Copy link
Owner

There is currently a problem when we try to set a new stream and play it directly after.
Taken from StationPlayerController.cpp

case radiostream::Event::NewStationRequested:
    {
        const auto station = std::any_cast<Station>(data);
        context_.status_.change_text(context_.localizer_.get_localized_text("Loading stream..."));
        context_.status_.change_color(StatusBar::Color::PROCESSING);
        context_.station_player_.set_station(station);
        context_.station_player_.play();
        context_.status_.change_text(context_.localizer_.get_localized_text("Stream playing"));
        context_.status_.change_color(StatusBar::Color::FINISHED);
    }
break;

Both StationPlayer::set_station() and StationPlayer::play() are implemented this way:

void StationPlayer::play()
{
    auto thread = std::thread([this]()
    {
        stream_manager_.play();
    });
    thread.detach();
}

and

void StationPlayer::set_station(const Station& station)
{
    station_ = station;
    auto thread = std::thread([this]()
    {
        stream_manager_.set_stream(station_.ip_);
        check_if_song_title_has_changed();
        notify(std::make_any<Station>(station_), radiostream::Event::StationBeingPlayedChanged);
    });
    thread.detach();
}

So it might happen that the thread that executes the play method might get created before the thread in set_station. In case of event mentioned above it makes it possible that play is executed before the set_station and in effect station will not start playing. This is unintended and should be fixed.

@khrynczenko
Copy link
Owner Author

Solved by #26 PR.

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

1 participant