Skip to content

Commit

Permalink
Set jl_stackbase (fixes JuliaLang#14028).
Browse files Browse the repository at this point in the history
An earlier commit removed jl_set_stackbase, but it was required
when building with JULIA_THREADS=1.  The fix makes jl_set_base_ctx
do the work that jl_set_stackbase did.
  • Loading branch information
Arch D. Robison authored and guolanting committed Nov 19, 2015
1 parent 7971ea1 commit 1e6c51e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
8 changes: 3 additions & 5 deletions src/task.c
Original file line number Diff line number Diff line change
Expand Up @@ -260,16 +260,15 @@ static void NOINLINE NORETURN start_task(void)
}

#ifdef COPY_STACKS
#ifndef ASM_COPY_STACKS
void NOINLINE jl_set_base_ctx(char *__stk)
{
jl_stackbase = (char*)(((uptrint_t)__stk + sizeof(*__stk))&-16); // also ensures stackbase is 16-byte aligned
#ifndef ASM_COPY_STACKS
if (jl_setjmp(jl_base_ctx, 1)) {
start_task();
}
}
#else
void jl_set_base_ctx(char *__stk) { }
#endif
}
#endif

DLLEXPORT void julia_init(JL_IMAGE_SEARCH rel)
Expand All @@ -278,7 +277,6 @@ DLLEXPORT void julia_init(JL_IMAGE_SEARCH rel)
_julia_init(rel);
#ifdef COPY_STACKS
char __stk;
jl_stackbase = (char*)(((uptrint_t)&__stk + sizeof(__stk))&-16); // also ensures stackbase is 16-byte aligned
jl_set_base_ctx(&__stk); // separate function, to record the size of a stack frame
#endif
}
Expand Down
17 changes: 9 additions & 8 deletions src/threading.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,9 @@ void ti_threadfun(void *arg)

// set up tasking
jl_init_root_task(0,0);
jl_set_stackbase((char*)&arg);
#ifdef COPY_STACKS
jl_set_base_ctx((char*)&arg);
#endif

// set the thread-local tid and wait for a thread group
while (ta->state == TI_THREAD_INIT)
Expand Down Expand Up @@ -165,7 +166,7 @@ void ti_threadfun(void *arg)
}

#if PROFILE_JL_THREADING
void ti_reset_timings();
void ti_reset_timings(void);
#endif

// interface to Julia; sets up to make the runtime thread-safe
Expand All @@ -184,9 +185,9 @@ void jl_init_threading(void)
jl_n_threads = jl_max_threads;

// set up space for per-thread heaps
jl_all_heaps = malloc(jl_n_threads * sizeof(void*));
jl_all_pgcstacks = malloc(jl_n_threads * sizeof(void*));
jl_all_task_states = malloc(jl_n_threads * sizeof(jl_thread_task_state_t));
jl_all_heaps = (struct _jl_thread_heap_t **)malloc(jl_n_threads * sizeof(void*));
jl_all_pgcstacks = (jl_gcframe_t ***)malloc(jl_n_threads * sizeof(void*));
jl_all_task_states = (jl_thread_task_state_t *)malloc(jl_n_threads * sizeof(jl_thread_task_state_t));

#if PROFILE_JL_THREADING
// estimate CPU speed
Expand Down Expand Up @@ -229,7 +230,7 @@ void jl_start_threads(void)
}

// create threads
targs = malloc((jl_n_threads - 1) * sizeof (ti_threadarg_t *));
targs = (ti_threadarg_t **)malloc((jl_n_threads - 1) * sizeof (ti_threadarg_t *));
for (i = 0; i < jl_n_threads - 1; ++i) {
targs[i] = (ti_threadarg_t *)malloc(sizeof (ti_threadarg_t));
targs[i]->state = TI_THREAD_INIT;
Expand Down Expand Up @@ -285,10 +286,10 @@ void jl_shutdown_threading(void)
}

// return thread's thread group
void *jl_threadgroup() { return (void *)tgworld; }
void *jl_threadgroup(void) { return (void *)tgworld; }

// utility
void jl_cpu_pause() { cpu_pause(); }
void jl_cpu_pause(void) { cpu_pause(); }

// interface to user code: specialize and compile the user thread function
// and run it in all threads
Expand Down

0 comments on commit 1e6c51e

Please sign in to comment.