From 8e8a7a018f5724e3f645ff6186879e6dcc195c94 Mon Sep 17 00:00:00 2001
From: wangzhengquan <wangzhengquan85@126.com>
Date: 星期六, 30 一月 2021 14:55:43 +0800
Subject: [PATCH] update
---
test/futex_test.cpp | 12 ++++++++----
1 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/test/futex_test.cpp b/test/futex_test.cpp
index 55d77f4..2e90999 100644
--- a/test/futex_test.cpp
+++ b/test/futex_test.cpp
@@ -46,6 +46,8 @@
{
int s;
+ sigset_t mask_all, pre;
+ sigfillset(&mask_all);
/* __sync_bool_compare_and_swap(ptr, oldval, newval) is a gcc
built-in function. It atomically performs the equivalent of:
@@ -60,11 +62,12 @@
/* Is the futex available? */
- if (__sync_bool_compare_and_swap(futexp, 1, 0))
+ if (__sync_bool_compare_and_swap(futexp, 1, 0)) {
+ sigprocmask(SIG_BLOCK, &mask_all, &pre);
break; /* Yes */
+ }
/* Futex is not available; wait */
-
s = futex(futexp, FUTEX_WAIT, 0, NULL, NULL, 0);
if (s == -1 && errno != EAGAIN)
errExit("futex-FUTEX_WAIT");
@@ -79,12 +82,14 @@
fpost(int *futexp)
{
int s;
-
+ sigset_t mask;
+ sigemptyset(&mask);
/* __sync_bool_compare_and_swap() was described in comments above */
if (__sync_bool_compare_and_swap(futexp, 0, 1)) {
s = futex(futexp, FUTEX_WAKE, 1, NULL, NULL, 0);
+ sigprocmask(SIG_SETMASK, &mask, NULL);
if (s == -1)
errExit("futex-FUTEX_WAKE");
}
@@ -137,7 +142,6 @@
}
/* State: available */
-
fwait(futex1);
printf("(%ld) 杩涘叆浜掓枼鍖篭n", (long) getpid());
sleep(5);
--
Gitblit v1.8.0