Skip to content

Commit a18ab97

Browse files
mbaumanJeffBezanson
authored andcommitted
Remove JULIA_ENABLE_THREADS feature flag (#32685)
This flag was essentially not documented, not CI'ed, and broken (it hangs in `jl_task_get_next at /home/mbauman/julia/src/partr.c:475`). Let's strip it out!
1 parent 419f541 commit a18ab97

22 files changed

+39
-241
lines changed

Make.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1145,7 +1145,7 @@ endif
11451145

11461146
# Threads
11471147
ifneq ($(JULIA_THREADS), 0)
1148-
JCPPFLAGS += -DJULIA_ENABLE_THREADING -DJULIA_NUM_THREADS=$(JULIA_THREADS)
1148+
JCPPFLAGS += -DJULIA_NUM_THREADS=$(JULIA_THREADS)
11491149
endif
11501150

11511151
# Intel VTune Amplifier

contrib/julia-config.jl

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,6 @@ function cflags(doframework)
8787
include = shell_escape(includeDir())
8888
print(flags, " -I", include)
8989
end
90-
if threadingOn()
91-
print(flags, " -DJULIA_ENABLE_THREADING=1")
92-
end
9390
if Sys.isunix()
9491
print(flags, " -fPIC")
9592
end

doc/src/manual/embedding.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,6 @@ We start by opening Visual Studio and creating a new Console Application project
148148
header file, add the following lines at the end:
149149

150150
```c
151-
#define JULIA_ENABLE_THREADING
152151
#include <julia.h>
153152
```
154153

src/gc.c

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,6 @@ NOINLINE uintptr_t gc_get_stack_ptr(void)
189189

190190
#define should_timeout() 0
191191

192-
#ifdef JULIA_ENABLE_THREADING
193192
static void jl_gc_wait_for_the_world(void)
194193
{
195194
if (jl_n_threads > 1)
@@ -207,11 +206,6 @@ static void jl_gc_wait_for_the_world(void)
207206
}
208207
}
209208
}
210-
#else
211-
static inline void jl_gc_wait_for_the_world(void)
212-
{
213-
}
214-
#endif
215209

216210
// malloc wrappers, aligned allocation
217211

@@ -1095,9 +1089,7 @@ JL_DLLEXPORT jl_value_t *jl_gc_pool_alloc(jl_ptls_t ptls, int pool_offset,
10951089
// to workaround a llvm bug.
10961090
// Ref https://llvm.org/bugs/show_bug.cgi?id=27190
10971091
jl_gc_pool_t *p = (jl_gc_pool_t*)((char*)ptls + pool_offset);
1098-
#ifdef JULIA_ENABLE_THREADING
10991092
assert(ptls->gc_state == 0);
1100-
#endif
11011093
#ifdef MEMDEBUG
11021094
return jl_gc_big_alloc(ptls, osize);
11031095
#endif
@@ -1452,12 +1444,6 @@ JL_DLLEXPORT void jl_gc_queue_root(jl_value_t *ptr)
14521444
{
14531445
jl_ptls_t ptls = jl_get_ptls_states();
14541446
jl_taggedvalue_t *o = jl_astaggedvalue(ptr);
1455-
#ifndef JULIA_ENABLE_THREADING
1456-
// Disable this assert since it can happen with multithreading (same
1457-
// with the ones in gc_queue_binding) when two threads are writing
1458-
// to the same object.
1459-
assert(o->bits.gc == GC_OLD_MARKED);
1460-
#endif
14611447
// The modification of the `gc_bits` is not atomic but it
14621448
// should be safe here since GC is not allowed to run here and we only
14631449
// write GC_OLD to the GC bits outside GC. This could cause
@@ -1471,10 +1457,6 @@ void gc_queue_binding(jl_binding_t *bnd)
14711457
{
14721458
jl_ptls_t ptls = jl_get_ptls_states();
14731459
jl_taggedvalue_t *buf = jl_astaggedvalue(bnd);
1474-
#ifndef JULIA_ENABLE_THREADING
1475-
// Will fail for multithreading. See `jl_gc_queue_root`
1476-
assert(buf->bits.gc == GC_OLD_MARKED);
1477-
#endif
14781460
buf->bits.gc = GC_MARKED;
14791461
arraylist_push(&ptls->heap.rem_bindings, bnd);
14801462
}
@@ -2496,9 +2478,7 @@ static void mark_roots(jl_gc_mark_cache_t *gc_cache, jl_gc_mark_sp_t *sp)
24962478
gc_mark_queue_obj(gc_cache, sp, jl_main_module);
24972479

24982480
// tasks
2499-
#ifdef JULIA_ENABLE_THREADING
25002481
jl_gc_mark_enqueued_tasks(gc_cache, sp);
2501-
#endif
25022482

25032483
// invisible builtin values
25042484
if (jl_an_empty_vec_any != NULL)

src/init.c

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -69,20 +69,19 @@ void jl_init_stack_limits(int ismaster, void **stack_lo, void **stack_hi)
6969
#ifdef _OS_WINDOWS_
7070
(void)ismaster;
7171
// https://en.wikipedia.org/wiki/Win32_Thread_Information_Block
72-
#ifdef _P64
72+
# ifdef _P64
7373
*stack_hi = (void**)__readgsqword(0x08); // Stack Base / Bottom of stack (high address)
7474
*stack_lo = (void**)__readgsqword(0x10); // Stack Limit / Ceiling of stack (low address)
75-
#else
75+
# else // !_P64
7676
*stack_hi = (void**)__readfsdword(0x04); // Stack Base / Bottom of stack (high address)
7777
*stack_lo = (void**)__readfsdword(0x08); // Stack Limit / Ceiling of stack (low address)
78-
#endif
79-
#else
80-
# ifdef JULIA_ENABLE_THREADING
78+
# endif // _P64
79+
#else // !_OS_WINDOWS_
8180
// Only use pthread_*_np functions to get stack address for non-master
8281
// threads since it seems to return bogus values for master thread on Linux
8382
// and possibly OSX.
8483
if (!ismaster) {
85-
# if defined(_OS_LINUX_)
84+
# if defined(_OS_LINUX_)
8685
pthread_attr_t attr;
8786
pthread_getattr_np(pthread_self(), &attr);
8887
void *stackaddr;
@@ -92,7 +91,7 @@ void jl_init_stack_limits(int ismaster, void **stack_lo, void **stack_hi)
9291
*stack_lo = (void*)stackaddr;
9392
*stack_hi = (void*)((char*)stackaddr + stacksize);
9493
return;
95-
# elif defined(_OS_DARWIN_)
94+
# elif defined(_OS_DARWIN_)
9695
extern void *pthread_get_stackaddr_np(pthread_t thread);
9796
extern size_t pthread_get_stacksize_np(pthread_t thread);
9897
pthread_t thread = pthread_self();
@@ -101,7 +100,7 @@ void jl_init_stack_limits(int ismaster, void **stack_lo, void **stack_hi)
101100
*stack_lo = (char*)stackaddr;
102101
*stack_hi = (void*)((char*)stackaddr + stacksize);
103102
return;
104-
# elif defined(_OS_FREEBSD_)
103+
# elif defined(_OS_FREEBSD_)
105104
pthread_attr_t attr;
106105
pthread_attr_init(&attr);
107106
pthread_attr_get_np(pthread_self(), &attr);
@@ -112,13 +111,10 @@ void jl_init_stack_limits(int ismaster, void **stack_lo, void **stack_hi)
112111
*stack_lo = (char*)stackaddr;
113112
*stack_hi = (void*)((char*)stackaddr + stacksize);
114113
return;
115-
# else
116-
# warning "Getting precise stack size for thread is not supported."
117-
# endif
118-
}
119114
# else
120-
(void)ismaster;
115+
# warning "Getting precise stack size for thread is not supported."
121116
# endif
117+
}
122118
struct rlimit rl;
123119
getrlimit(RLIMIT_STACK, &rl);
124120
size_t stack_size = rl.rlim_cur;
@@ -651,10 +647,8 @@ static void jl_set_io_wait(int v)
651647
void _julia_init(JL_IMAGE_SEARCH rel)
652648
{
653649
jl_init_timing();
654-
#ifdef JULIA_ENABLE_THREADING
655650
// Make sure we finalize the tls callback before starting any threads.
656651
jl_get_ptls_states_getter();
657-
#endif
658652
jl_ptls_t ptls = jl_get_ptls_states();
659653
(void)ptls; assert(ptls); // make sure early that we have initialized ptls
660654
jl_safepoint_init();

src/julia.h

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1515,12 +1515,11 @@ typedef enum {
15151515
JL_IMAGE_JULIA_HOME = 1,
15161516
//JL_IMAGE_LIBJULIA = 2,
15171517
} JL_IMAGE_SEARCH;
1518-
#ifdef JULIA_ENABLE_THREADING
15191518
// this helps turn threading compilation mismatches into linker errors
15201519
#define julia_init julia_init__threading
15211520
#define jl_init jl_init__threading
15221521
#define jl_init_with_image jl_init_with_image__threading
1523-
#endif
1522+
15241523
JL_DLLEXPORT void julia_init(JL_IMAGE_SEARCH rel);
15251524
JL_DLLEXPORT void jl_init(void);
15261525
JL_DLLEXPORT void jl_init_with_image(const char *julia_bindir,
@@ -1656,9 +1655,7 @@ typedef struct _jl_handler_t {
16561655
jl_gcframe_t *gcstack;
16571656
struct _jl_handler_t *prev;
16581657
int8_t gc_state;
1659-
#ifdef JULIA_ENABLE_THREADING
16601658
size_t locks_len;
1661-
#endif
16621659
sig_atomic_t defer_signal;
16631660
int finalizers_inhibited;
16641661
jl_timing_block_t *timing_stack;
@@ -1700,10 +1697,8 @@ typedef struct _jl_task_t {
17001697
int16_t tid;
17011698
/* for the multiqueue */
17021699
int16_t prio;
1703-
#ifdef JULIA_ENABLE_THREADING
17041700
// This is statically initialized when the task is not holding any locks
17051701
arraylist_t locks;
1706-
#endif
17071702
jl_timing_block_t *timing_stack;
17081703
} jl_task_t;
17091704

@@ -2019,7 +2014,7 @@ typedef struct {
20192014
extern JL_DLLEXPORT jl_cgparams_t jl_default_cgparams;
20202015
extern JL_DLLEXPORT int jl_default_debug_info_kind;
20212016

2022-
#if defined(JULIA_ENABLE_THREADING) && !defined(_OS_DARWIN_) && !defined(_OS_WINDOWS_)
2017+
#if !defined(_OS_DARWIN_) && !defined(_OS_WINDOWS_)
20232018
#define JULIA_DEFINE_FAST_TLS() \
20242019
JL_DLLEXPORT JL_CONST_FUNC jl_ptls_t jl_get_ptls_states_static(void) \
20252020
{ \

src/julia_internal.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ void jl_safepoint_defer_sigint(void);
540540
int jl_safepoint_consume_sigint(void);
541541
void jl_wake_libuv(void);
542542

543-
#if defined(JULIA_ENABLE_THREADING) && !defined(__clang_analyzer__)
543+
#if !defined(__clang_analyzer__)
544544
jl_get_ptls_states_func jl_get_ptls_states_getter(void);
545545
static inline void jl_set_gc_and_wait(void)
546546
{
@@ -853,7 +853,7 @@ extern jl_mutex_t safepoint_lock;
853853

854854
// -- gc.c -- //
855855

856-
#if defined(__APPLE__) && defined(JULIA_ENABLE_THREADING)
856+
#if defined(__APPLE__)
857857
void jl_mach_gc_end(void);
858858
#endif
859859

src/julia_threads.h

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@
1111
// Nonetheless, we define JL_THREAD and use it to give advanced notice to
1212
// maintainers of what eventual threading support will change.
1313

14-
// JULIA_ENABLE_THREADING is switched on in Make.inc if JULIA_THREADS is
15-
// set (in Make.user)
16-
1714
// Options for task switching algorithm (in order of preference):
1815
// JL_HAVE_ASM -- mostly setjmp
1916
// JL_HAVE_ASYNCIFY -- task switching based on the binaryen asyncify transform
@@ -274,16 +271,6 @@ void jl_sigint_safepoint(jl_ptls_t tls) JL_NOTSAFEPOINT;
274271
(void)safepoint_load; \
275272
} while (0)
276273
#endif
277-
#ifndef JULIA_ENABLE_THREADING
278-
#define jl_gc_state(ptls) ((int8_t)0)
279-
STATIC_INLINE int8_t jl_gc_state_set(jl_ptls_t ptls, int8_t state,
280-
int8_t old_state)
281-
{
282-
(void)ptls;
283-
(void)state;
284-
return old_state;
285-
}
286-
#else // ifndef JULIA_ENABLE_THREADING
287274
// Make sure jl_gc_state() is always a rvalue
288275
#define jl_gc_state(ptls) ((int8_t)ptls->gc_state)
289276
STATIC_INLINE int8_t jl_gc_state_set(jl_ptls_t ptls, int8_t state,
@@ -296,7 +283,6 @@ STATIC_INLINE int8_t jl_gc_state_set(jl_ptls_t ptls, int8_t state,
296283
jl_gc_safepoint_(ptls);
297284
return old_state;
298285
}
299-
#endif // ifndef JULIA_ENABLE_THREADING
300286
STATIC_INLINE int8_t jl_gc_state_save_and_set(jl_ptls_t ptls,
301287
int8_t state)
302288
{

src/llvm-ptls.cpp

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,8 @@
2121
#include <llvm/IR/LLVMContext.h>
2222
#include <llvm/IR/MDBuilder.h>
2323

24-
#if defined(JULIA_ENABLE_THREADING)
25-
# include <llvm/IR/InlineAsm.h>
26-
# include <llvm/Transforms/Utils/BasicBlockUtils.h>
27-
#endif
24+
#include <llvm/IR/InlineAsm.h>
25+
#include <llvm/Transforms/Utils/BasicBlockUtils.h>
2826

2927
#include "julia.h"
3028
#include "julia_internal.h"
@@ -61,21 +59,16 @@ struct LowerPTLS: public ModulePass {
6159
Type *T_int8;
6260
Type *T_size;
6361
PointerType *T_pint8;
64-
#ifdef JULIA_ENABLE_THREADING
6562
GlobalVariable *ptls_slot{nullptr};
6663
GlobalVariable *ptls_offset{nullptr};
6764
void set_ptls_attrs(CallInst *ptlsStates) const;
6865
Instruction *emit_ptls_tp(Value *offset, Instruction *insertBefore) const;
6966
template<typename T> T *add_comdat(T *G) const;
7067
GlobalVariable *create_aliased_global(Type *T, StringRef name) const;
71-
#else
72-
GlobalVariable *static_tls;
73-
#endif
7468
void fix_ptls_use(CallInst *ptlsStates);
7569
bool runOnModule(Module &M) override;
7670
};
7771

78-
#ifdef JULIA_ENABLE_THREADING
7972
void LowerPTLS::set_ptls_attrs(CallInst *ptlsStates) const
8073
{
8174
ptlsStates->addAttribute(AttributeList::FunctionIndex, Attribute::ReadNone);
@@ -182,7 +175,6 @@ inline T *LowerPTLS::add_comdat(T *G) const
182175
#endif
183176
return G;
184177
}
185-
#endif
186178

187179
void LowerPTLS::fix_ptls_use(CallInst *ptlsStates)
188180
{
@@ -191,7 +183,6 @@ void LowerPTLS::fix_ptls_use(CallInst *ptlsStates)
191183
return;
192184
}
193185

194-
#ifdef JULIA_ENABLE_THREADING
195186
if (imaging_mode) {
196187
if (jl_tls_elf_support) {
197188
// if (offset != 0)
@@ -245,10 +236,6 @@ void LowerPTLS::fix_ptls_use(CallInst *ptlsStates)
245236
ptlsStates->setCalledFunction(ptlsStates->getFunctionType(), ConstantExpr::getIntToPtr(val, T_ptls_getter));
246237
set_ptls_attrs(ptlsStates);
247238
}
248-
#else
249-
ptlsStates->replaceAllUsesWith(static_tls);
250-
ptlsStates->eraseFromParent();
251-
#endif
252239
}
253240

254241
bool LowerPTLS::runOnModule(Module &_M)
@@ -268,15 +255,10 @@ bool LowerPTLS::runOnModule(Module &_M)
268255
T_int8 = Type::getInt8Ty(*ctx);
269256
T_size = sizeof(size_t) == 8 ? Type::getInt64Ty(*ctx) : Type::getInt32Ty(*ctx);
270257
T_pint8 = T_int8->getPointerTo();
271-
#ifdef JULIA_ENABLE_THREADING
272258
if (imaging_mode) {
273259
ptls_slot = create_aliased_global(T_ptls_getter, "jl_get_ptls_states_slot");
274260
ptls_offset = create_aliased_global(T_size, "jl_tls_offset");
275261
}
276-
#else
277-
static_tls = new GlobalVariable(*M, T_ppjlvalue, false, GlobalVariable::ExternalLinkage,
278-
NULL, "jl_tls_states");
279-
#endif
280262

281263
for (auto it = ptls_getter->user_begin(); it != ptls_getter->user_end();) {
282264
auto call = cast<CallInst>(*it);

src/locks.h

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ static inline void jl_mutex_lock_nogc(jl_mutex_t *lock) JL_NOTSAFEPOINT
5151
#endif
5252
}
5353

54-
#ifdef JULIA_ENABLE_THREADING
5554
static inline void jl_lock_frame_push(jl_mutex_t *lock)
5655
{
5756
jl_ptls_t ptls = jl_get_ptls_states();
@@ -75,15 +74,6 @@ static inline void jl_lock_frame_pop(void)
7574
ptls->current_task->locks.len--;
7675
}
7776
}
78-
#else
79-
static inline void jl_lock_frame_push(jl_mutex_t *lock)
80-
{
81-
(void)lock;
82-
}
83-
static inline void jl_lock_frame_pop(void)
84-
{
85-
}
86-
#endif // ifndef JULIA_ENABLE_THREADING
8777

8878
#define JL_SIGATOMIC_BEGIN() do { \
8979
jl_get_ptls_states()->defer_signal++; \
@@ -181,31 +171,11 @@ static inline void jl_mutex_init(jl_mutex_t *lock) JL_NOTSAFEPOINT
181171
lock->count = 0;
182172
}
183173

184-
#ifdef JULIA_ENABLE_THREADING
185174
#define JL_MUTEX_INIT(m) jl_mutex_init(m)
186175
#define JL_LOCK(m) jl_mutex_lock(m)
187176
#define JL_UNLOCK(m) jl_mutex_unlock(m)
188177
#define JL_LOCK_NOGC(m) jl_mutex_lock_nogc(m)
189178
#define JL_UNLOCK_NOGC(m) jl_mutex_unlock_nogc(m)
190-
#else // JULIA_ENABLE_THREADING
191-
static inline void jl_mutex_check_type(jl_mutex_t *m) JL_NOTSAFEPOINT
192-
{
193-
(void)m;
194-
}
195-
#define JL_MUTEX_INIT(m) jl_mutex_check_type(m)
196-
#define JL_LOCK(m) do { \
197-
JL_SIGATOMIC_BEGIN(); \
198-
jl_gc_enable_finalizers(jl_get_ptls_states(), 0); \
199-
jl_mutex_check_type(m); \
200-
} while (0)
201-
#define JL_UNLOCK(m) do { \
202-
jl_gc_enable_finalizers(jl_get_ptls_states(), 1); \
203-
jl_mutex_check_type(m); \
204-
JL_SIGATOMIC_END(); \
205-
} while (0)
206-
#define JL_LOCK_NOGC(m) jl_mutex_check_type(m)
207-
#define JL_UNLOCK_NOGC(m) jl_mutex_check_type(m)
208-
#endif // JULIA_ENABLE_THREADING
209179

210180
#ifdef __cplusplus
211181
}

0 commit comments

Comments
 (0)