Comment by yxhuvud

Comment by yxhuvud a day ago

5 replies

Green threads have issues with C FFI mostly due to not being able to preempt execution, when the C thing is doing something that blocks. This is a problem when you have one global pool of threads that execute everything. To get around it you essentially need to set up a dedicated thread pool to handle those c calls.

Which may be fine - go doesn't let the user directly create thread pools directly but do create one under the hood for ffi interaction.

layer8 a day ago

The problem is when C calls expect to be on a particular thread. Either the main event thread, in a GUI context, or the same thread as some related previous call.

  • ori_b a day ago

    The problem is that C expects to have enough stack to put stuff there, but green threads allocate small stacks to reduce (virtual) memory use.

    • layer8 21 hours ago

      That’s not a problem when a dedicated thread pool is used as mentioned by GP. However they don’t solve the thread affinity issue.

      • ori_b 12 hours ago

        That's the reason for the thread pool, and the resulting thread affinity issue.

        • layer8 7 hours ago

          This seems to assume that the same green thread will always run on the same native thread, which I don’t think is universally the case.