{"action":"created","issue":{"url":"https://api.github.com/repos/JuliaLang/julia/issues/10421","labels_url":"https://api.github.com/repos/JuliaLang/julia/issues/10421/labels{/name}","comments_url":"https://api.github.com/repos/JuliaLang/julia/issues/10421/comments","events_url":"https://api.github.com/repos/JuliaLang/julia/issues/10421/events","html_url":"https://github.com/JuliaLang/julia/issues/10421","id":60113585,"number":10421,"title":"Thread safety tracker","user":{"login":"ViralBShah","id":744411,"avatar_url":"https://avatars.githubusercontent.com/u/744411?v=3","gravatar_id":"","url":"https://api.github.com/users/ViralBShah","html_url":"https://github.com/ViralBShah","followers_url":"https://api.github.com/users/ViralBShah/followers","following_url":"https://api.github.com/users/ViralBShah/following{/other_user}","gists_url":"https://api.github.com/users/ViralBShah/gists{/gist_id}","starred_url":"https://api.github.com/users/ViralBShah/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ViralBShah/subscriptions","organizations_url":"https://api.github.com/users/ViralBShah/orgs","repos_url":"https://api.github.com/users/ViralBShah/repos","events_url":"https://api.github.com/users/ViralBShah/events{/privacy}","received_events_url":"https://api.github.com/users/ViralBShah/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/JuliaLang/julia/labels/multi-threading","name":"multi-threading","color":"fbca04"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":43,"created_at":"2015-03-06T15:10:20Z","updated_at":"2015-03-26T17:26:20Z","closed_at":null,"body":"One of the first things we need to do is make the runtime thread safe. This work is on the `threads` branch, and this tracker predates the new GC. I thought it is worth capturing a tracker that @StefanKarpinski prepared earlier in an issue to ease the thread safety work.\r\n\r\nThis list is organized as `Variable; Approach`\r\n\r\nbuiltins.c\r\n========\r\n- [ ] extern size_t jl_page_size;       constant\r\n- [x] extern int jl_in_inference;       lock\r\n- [x] extern int jl_boot_file_loaded;   constant\r\n- [ ] int in_jl_ = 0;                   thread-local\r\n\r\nccall.cpp\r\n==\r\n- [ ] static std::map<std::stringstd::string> sonameMap;        lock\r\n- [ ] static bool got_sonames = false;        lock, write-once\r\n- [ ] static std::map<std::stringuv_lib_t*> libMap; lock\r\n- [ ] static std::map<std::stringGlobalVariable*> libMapGV;     lock\r\n- [ ] static std::map<std::stringGlobalVariable*> symMapGV;     lock\r\n- [ ] ~~static char *temp_arg_area;                 thread-local (will be deleted very soon)~~\r\n- [x] ~~static const uint32_t arg_area_sz = 4196;   constant (will be deleted very soon)~~\r\n- [ ] ~~static uint32_t arg_area_loc;     thread-local (will be deleted very soon)~~\r\n- [ ] ~~static void *temp_arg_blocks[N_TEMP_ARG_BLOCKS];  thread-local (will be deleted very soon)~~\r\n- [ ] ~~static uint32_t arg_block_n = 0;                  thread-local (will be deleted  very soon)~~\r\n- [x] ~~static Function *save_arg_area_loc_func;          constant (will be deleted very soon)~~\r\n- [x] ~~static Function *restore_arg_area_loc_func;       constant (will be deleted very soon)~~\r\n\r\ncgutils.cpp\r\n==\r\n- [x] static std::map<const std::stringGlobalVariable*> stringConstants;        lock\r\n- [x] static std::map<void*jl_value_llvm> jl_value_to_llvm;                     lock\r\n- [x] static std::map<Value *void*> llvm_to_jl_value;                           lock\r\n- [x] static std::vector<Constant*> jl_sysimg_gvars;                            lock\r\n- [x] static std::map<intjl_value_t*> typeIdToType;                             lock\r\n- [x] jl_array_t *typeToTypeId;       lock\r\n- [x] static int cur_type_id = 1;     lock\r\n\r\ncodegen.cpp\r\n==\r\n- [ ] void *__stack_chk_guard = NULL;   thread-local (jwn: why is this on the list? it's a constant and not thread local)\r\n\r\ndebuginfo.cpp\r\n==\r\n- [ ] extern \"C\" volatile int jl_in_stackwalk;\r\n- [ ] JuliaJITEventListener *jl_jit_events;\r\n- [ ] static obfiletype objfilemap;\r\n- [x] extern char *jl_sysimage_name;    constant\r\n- [ ] static logdata_t coverageData;\r\n- [ ] static logdata_t mallocData;\r\n\r\ndump.c\r\n==\r\n- [ ] static jl_array_t *tree_literal_values=NULL;      thread-local\r\n- [x] static jl_value_t *jl_idtable_type=NULL;          constant\r\n- [x] static jl_array_t *datatype_list=NULL;            thread 0 only\r\n- [x] jl_value_t ***sysimg_gvars = NULL;                thread 0 only\r\n- [x] extern int globalUnique;   thread 0 only\r\n- [x] static size_t delayed_fptrs_n = 0;  thread 0 only\r\n- [x] static size_t delayed_fptrs_max = 0;       thread 0 only\r\n\r\ngc.c\r\n==\r\n- [ ] static volatile size_t allocd_bytes = 0;  thread-local\r\n- [ ] static volatile int64_t total_allocd_bytes = 0;   thread-local\r\n- [ ] static int64_t last_gc_total_bytes = 0;    thread-local\r\n- [x] static size_t freed_bytes = 0;     barrier\r\n- [x] static uint64_t total_gc_time=0;   barrier\r\n- [x] int jl_in_gc=0; * referenced from switchto task.c        barrier\r\n- [x] static htable_t obj_counts;   barrier\r\n- [x] static size_t total_freed_bytes=0;          barrier\r\n- [x] static arraylist_t to_finalize;             barrier\r\n- [x] static jl_value_t **mark_stack = NULL;      barrier\r\n- [x] static size_t mark_stack_size = 0;          barrier\r\n- [x] static size_t mark_sp = 0;    barrier\r\n- [x] extern jl_module_t *jl_old_base_module;     constant\r\n- [x] extern jl_array_t *typeToTypeId;            barrier\r\n- [x] extern jl_array_t *jl_module_init_order;    barrier\r\n- [x] static int is_gc_enabled = 1;               atomic\r\n- [x] static double process_t0;  constant\r\n\r\ninit.c\r\n==\r\n- [x] char *jl_stack_lo;        constant\r\n- [x] char *jl_stack_hi;        constant\r\n- [ ] volatile sig_atomic_t jl_signal_pending = 0;      thread-local\r\n- [ ] volatile sig_atomic_t jl_defer_signal = 0;        thread-local\r\n- [ ] uv_loop_t *jl_io_loop;                I/O thread ?\r\n- [ ] static void *signal_stack;            thread-local (see https://github.com/JuliaLang/julia/issues/9763#issuecomment-69864396)\r\n- [x] static mach_port_t segv_port = 0;     constant\r\n- [ ] extern void * __stack_chk_guard;      thread-local (duplicate of above)\r\n\r\njltypes.c\r\n==\r\n- [ ] int inside_typedef = 0;   thread-local\r\n- [ ] static int match_intersection_mode = 0;   thread-local\r\n- [ ] static int has_ntuple_intersect_tuple = 0;        thread-local\r\n- [ ] static int t_uid_ctr = 1;             lock\r\n\r\nllvm-simdloop.cpp\r\n==\r\n- [x] static unsigned simd_loop_mdkind = 0;     constant\r\n- [x] static MDNode* simd_loop_md = NULL;       constant\r\n- [x] char LowerSIMDLoop::ID = 0; lock\r\n\r\nmodule.c\r\n==\r\n- [x] jl_module_t *jl_main_module=NULL; constant\r\n- [x] jl_module_t *jl_core_module=NULL; constant\r\n- [x] jl_module_t *jl_base_module=NULL; constant\r\n- [ ] jl_module_t *jl_current_module=NULL;              thread-local\r\n- [ ] jl_array_t *jl_module_init_order = NULL;          lock (this code is bady broken anyways: https://github.com/JuliaLang/julia/issues/9799)\r\n\r\nprofile.c\r\n==\r\n- [ ] static volatile ptrint_t* bt_data_prof = NULL;\r\n- [ ] static volatile size_t bt_size_max = 0;\r\n- [ ] static volatile size_t bt_size_cur = 0;\r\n- [ ] static volatile u_int64_t nsecprof = 0;\r\n- [ ] static volatile int running = 0;\r\n- [ ] volatile HANDLE hBtThread = 0;\r\n- [ ] static pthread_t profiler_thread;\r\n- [ ] static mach_port_t main_thread;\r\n- [ ] clock_serv_t clk;\r\n- [ ] static int profile_started = 0;\r\n- [ ] static mach_port_t profile_port = 0;\r\n- [ ] volatile static int forceDwarf = -2;\r\n- [ ] volatile mach_port_t mach_profiler_thread = 0;\r\n- [ ] static unw_context_t profiler_uc;\r\n- [ ] mach_timespec_t timerprof;\r\n- [ ] struct itimerval timerprof;\r\n- [ ] static timer_t timerprof;\r\n- [ ] static struct itimerspec itsprof;\r\n\r\nsys.c\r\n==\r\n- [x] JL_STREAM *JL_STDIN=0;    constant\r\n- [x] JL_STREAM *JL_STDOUT=0;   constant\r\n- [x] JL_STREAM *JL_STDERR=0;   constant\r\n\r\ntask.c\r\n==\r\n- [ ] volatile int jl_in_stackwalk = 0; thread-local\r\n- [x] static size_t _frame_offset; constant\r\n- [x] DLLEXPORT jl_task_t * volatile jl_current_task;   thread-local\r\n- [x] jl_task_t *jl_root_task;       constant\r\n- [x] jl_value_t * volatile jl_task_arg_in_transit;     thread-local\r\n- [x] jl_value_t *jl_exception_in_transit;              thread-local\r\n- [x] __JL_THREAD jl_gcframe_t *jl_pgcstack = NULL;     thread-local\r\n- [x] jl_jmp_buf * volatile jl_jmp_target;  thread-local\r\n- [x] extern int jl_in_gc;  barrier\r\n- [x] static jl_function_t *task__hook_func=NULL;   constant\r\n- [x] ptrint_t bt_data[MAX_BT_SIZE+1];                  thread-local\r\n- [ ] size_t bt_size = 0;                               thread-local\r\n- [ ] int needsSymRefreshModuleList;                    lock\r\n- [x] jl_function_t *jl_unprotect_stack_func;           constant\r\n\r\ntoplevel.c\r\n==\r\n- [ ] int jl_lineno = 0;        thread-local\r\n- [x] jl_module_t *jl_old_base_module = NULL;   constant\r\n- [x] jl_module_t *jl_internal_main_module = NULL;              constant\r\n- [x] extern int jl_in_inference;          lock\r\n"},"comment":{"url":"https://api.github.com/repos/JuliaLang/julia/issues/comments/86632328","html_url":"https://github.com/JuliaLang/julia/issues/10421#issuecomment-86632328","issue_url":"https://api.github.com/repos/JuliaLang/julia/issues/10421","id":86632328,"user":{"login":"garrison","id":91987,"avatar_url":"https://avatars.githubusercontent.com/u/91987?v=3","gravatar_id":"","url":"https://api.github.com/users/garrison","html_url":"https://github.com/garrison","followers_url":"https://api.github.com/users/garrison/followers","following_url":"https://api.github.com/users/garrison/following{/other_user}","gists_url":"https://api.github.com/users/garrison/gists{/gist_id}","starred_url":"https://api.github.com/users/garrison/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/garrison/subscriptions","organizations_url":"https://api.github.com/users/garrison/orgs","repos_url":"https://api.github.com/users/garrison/repos","events_url":"https://api.github.com/users/garrison/events{/privacy}","received_events_url":"https://api.github.com/users/garrison/received_events","type":"User","site_admin":false},"created_at":"2015-03-26T17:26:20Z","updated_at":"2015-03-26T17:26:20Z","body":"Glancing at `alloc.c`, I noticed a few things that are missing from the list/spreadsheet above: `gs_ctr` should be made per-thread, and `jl_gensym` and `jl_tagged_genym` both return static buffers.  There may be other things in this file as well that are not thread safe (I have not checked thoroughly)."}}