# Problem combining worker processes and threads

**URL:** <https://discourse.julialang.org/t/problem-combining-worker-processes-and-threads/64069>\
**Category:** General Usage\
**Tags:** question\
**Created:** [July 5, 2021, 10:51am UTC](https://discourse.julialang.org/t/problem-combining-worker-processes-and-threads/64069 "2021-07-05T10:51:05Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![jpsamaroo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jpsamaroo/32/46804_2.png) [@jpsamaroo](https://discourse.julialang.org/u/jpsamaroo)\
**Post date:** [July 5, 2021, 1:05pm UTC](https://discourse.julialang.org/t/problem-combining-worker-processes-and-threads/64069/2 "2021-07-05T13:05:19Z")

</div>

> [@orenbenkiki](#):
>
> GC crashing on “task switch within GC” (which really “can’t happen”). I only saw this once.

This isn’t a GC “crash”, this is just a regular error from a finalizer (which looks like a crash because it shows a non-fancy stacktrace). The issue is that `WeakKeyDict` uses a `ReentrantLock` internally to ensure consistency, but trying to lock that within a finalizer can sometimes cause a `yield()`, which is not valid in a finalizer. I believe this should be fixed by [fix numerous issues with WeakKeyDict by vtjnash · Pull Request #38180 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/pull/38180).

The rest of the errors I’m not sure about since I haven’t looked at your code for very long. Can you post an MWE that exhibits the bugs in question? The above code snippet doesn’t define `COUNTERS`, and doesn’t qualify `nthreads()`; once I set `COUNTERS=100` and made the definition `Threads.nthreads()`, it ran fine for me with 6 threads and 6 processes. Am I supposed to call `next!()` to reproduce the bug?

---

_[View the full topic](https://discourse.julialang.org/t/problem-combining-worker-processes-and-threads/64069)._
