Skip to content

Conversation

@ihsandemir
Copy link
Collaborator

Wait the thread to actually finish before the Thread destructor exits. Also use weak_ptr in ShutdownTask to prevent cyclic reference problem of shared_ptr.

fixes #429

…. Also use weak_ptr in ShutdownTask to prevent cyclic reference problem of shared_ptr.

fixes hazelcast#429
@ihsandemir ihsandemir added this to the 3.10.1 milestone Aug 10, 2018
@ihsandemir ihsandemir self-assigned this Aug 10, 2018
@ihsandemir ihsandemir changed the title Wait the thread to actually finish before the Thread destructor exits… Wait the thread to actually finish before the Thread destructor exits Aug 10, 2018
@devOpsHazelcast
Copy link
Contributor

Windows test FAILed.

1 similar comment
@devOpsHazelcast
Copy link
Contributor

Windows test FAILed.

@devOpsHazelcast
Copy link
Contributor

Linux test PASSed.

1 similar comment
@devOpsHazelcast
Copy link
Contributor

Linux test PASSed.

@devOpsHazelcast
Copy link
Contributor

Windows test PASSed.

@devOpsHazelcast
Copy link
Contributor

Linux test PASSed.

AbstractThread::~AbstractThread() {
if (started) {
int state = stateLatch->get();
if (state == 1) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this if statement necessary. It looks like the second count is doing same thing as started boolean. I would remove the second count that tracks started.

And there seems to be still race between destructor and start method.
When both starts at the same time, it could be the case that destructor passes then thread starts.
To prevent that, ( I am asking because I am not sure about usages of abstractThread )
there needs to be a third state and started that we set on destructor so that start will be prevented.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Changed the Thread implementation to use state machine. The states are :
enum ThreadState {
UNSTARTED = 0,
STARTED = 1,
JOINED = 2,
CANCELLED = 3
};
It can go from UNSTARTED to STARTED, STARTED to JOINED or STARTED to CANCELLED states. Other transitions are not valid. When thread is cancelled, then the shutdown latch is waited.

                enum ThreadState {
                    UNSTARTED = 0,
                    STARTED = 1,
                    JOINED = 2,
                    CANCELLED = 3
                };
It can go from UNSTARTED to STARTED, STARTED to JOINED or STARTED to CANCELLED states. Other transitions are not valid. When thread is cancelled, then the shutdown latch is waited.
@devOpsHazelcast
Copy link
Contributor

Windows test PASSed.

@devOpsHazelcast
Copy link
Contributor

Linux test PASSed.

@ihsandemir ihsandemir merged commit ac668ea into hazelcast:master Aug 13, 2018
@ihsandemir ihsandemir deleted the threadDestructorFix branch August 13, 2018 12:49
ihsandemir added a commit to ihsandemir/hazelcast-cpp-client that referenced this pull request Jul 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

C++ client crashes when server doesn't respond to HB

3 participants