Skip to content

Commit 31ca0ed

Browse files
Make encoder internal arrays thread_local for thread safety (#42)
Co-authored-by: deepak.gowthaman <[email protected]>
1 parent db9379d commit 31ca0ed

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

include/alp/encoder.hpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -311,9 +311,12 @@ struct encoder {
311311
ST* encoded_integers,
312312
const factor_idx_t factor_idx,
313313
const exponent_idx_t exponent_idx) {
314-
alignas(64) static PT ENCODED_VALUE_ARR[1024];
315-
alignas(64) static PT VALUE_ARR_WITHOUT_SPECIALS[1024];
316-
alignas(64) static UT TMP_INDEX_ARR[1024];
314+
// These arrays are thread_local static to ensure thread safety during multithreaded compression.
315+
// See: https://github.com/cwida/ALP/issues/41 for discussion.
316+
// Without thread_local, static arrays would be shared between threads, causing data races.
317+
alignas(64) thread_local static PT ENCODED_VALUE_ARR[1024];
318+
alignas(64) thread_local static PT VALUE_ARR_WITHOUT_SPECIALS[1024];
319+
alignas(64) thread_local static UT TMP_INDEX_ARR[1024];
317320

318321
exp_p_t current_exceptions_count {0};
319322
uint64_t exceptions_idx {0};

0 commit comments

Comments
 (0)