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

open_posix_testsuite: fix pthread_cond_destroy test error. #1097

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,9 @@ static void *child(void *arg PTS_ATTRIBUTE_UNUSED)
UNRESOLVED(ret, "Failed to wait for the cond");
}

/* unlock the mutex */
td->count2--;

/* unlock the mutex */
ret = pthread_mutex_unlock(&td->mtx2);
if (ret != 0) {
UNRESOLVED(ret, "Failed to unlock the mutex.");
Expand Down Expand Up @@ -603,6 +605,23 @@ int main(void)
p_child);
}

/* Make sure all children have exited the first wait */
ch = td->count1;
while (ch > 0) {
ret = pthread_mutex_unlock(&td->mtx1);
if (ret != 0) {
UNRESOLVED_KILLALL(
ret, "Failed to unlock mutex", p_child);
}
sched_yield();
ret = pthread_mutex_lock(&td->mtx1);
if (ret != 0) {
UNRESOLVED_KILLALL(ret, "Failed to lock mutex",
p_child);
}
ch = td->count1;
}

ret = pthread_mutex_unlock(&td->mtx1);
if (ret != 0) {
UNRESOLVED_KILLALL(ret, "Failed to unlock mutex",
Expand All @@ -625,35 +644,6 @@ int main(void)
("[parent] Condition was broadcasted, and condvar destroyed.\n");
#endif

/* Make sure all children have exited the first wait */
ret = pthread_mutex_lock(&td->mtx1);
if (ret != 0) {
UNRESOLVED_KILLALL(ret, "Failed to lock mutex",
p_child);
}
ch = td->count1;
while (ch > 0) {
ret = pthread_mutex_unlock(&td->mtx1);
if (ret != 0) {
UNRESOLVED_KILLALL(ret,
"Failed to unlock mutex",
p_child);
}
sched_yield();
ret = pthread_mutex_lock(&td->mtx1);
if (ret != 0) {
UNRESOLVED_KILLALL(ret, "Failed to lock mutex",
p_child);
}
ch = td->count1;
}

ret = pthread_mutex_unlock(&td->mtx1);
if (ret != 0) {
UNRESOLVED_KILLALL(ret, "Failed to unlock mutex",
p_child);
}

/* Go toward the 2nd pass */
/* Now, all children are waiting to lock the 2nd mutex, which we own here. */
/* reinitialize the condvar */
Expand Down Expand Up @@ -697,6 +687,23 @@ int main(void)
p_child);
}

/* Make sure all children have exited the second wait */
ch = td->count2;
while (ch > 0) {
ret = pthread_mutex_unlock(&td->mtx2);
if (ret != 0) {
UNRESOLVED_KILLALL(
ret, "Failed to unlock mutex", p_child);
}
sched_yield();
ret = pthread_mutex_lock(&td->mtx2);
if (ret != 0) {
UNRESOLVED_KILLALL(ret, "Failed to lock mutex",
p_child);
}
ch = td->count2;
}

/* Allow the children to terminate */
ret = pthread_mutex_unlock(&td->mtx2);
if (ret != 0) {
Expand Down