Skip to content

Commit 41bce9a

Browse files
committed
using mutex before memcpy
1 parent 76d823f commit 41bce9a

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

quaddtype/numpy_quaddtype/src/quaddtype_main.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
#include "quad_common.h"
1919
#include "quadblas_interface.h"
2020
#include "float.h"
21+
#include <pthread.h>
22+
23+
static pthread_mutex_t constant_mutex = PTHREAD_MUTEX_INITIALIZER;
2124

2225
static PyObject *
2326
py_is_longdouble_128(PyObject *self, PyObject *args)
@@ -75,6 +78,7 @@ get_sleef_constant(PyObject *self, PyObject *args)
7578
// On platforms with native __float128 support, use the correct literal
7679
result->value.sleef_value = SLEEF_QUAD_DENORM_MIN;
7780
#else
81+
pthread_mutex_lock(&constant_mutex);
7882
// On platforms without native __float128, SLEEF_QUAD_DENORM_MIN is broken
7983
// Manually constructing the smallest subnormal: 1 * 2^(-16382-112) = 2^(-16494)
8084
// This represents 0x0.0000000000000000000000000001p-16382
@@ -90,6 +94,7 @@ get_sleef_constant(PyObject *self, PyObject *args)
9094
c.h = 0x0000000000000000ULL; // exponent = 0 (subnormal), mantissa high = 0
9195
c.l = 0x0000000000000001ULL; // mantissa low = 1 (smallest possible)
9296
memcpy(&result->value.sleef_value, &c, 16);
97+
pthread_mutex_unlock(&constant_mutex);
9398
#endif
9499
}
95100
else if (strcmp(constant_name, "bits") == 0) {

0 commit comments

Comments
 (0)