# Does stdlib network sockets use only first thread?

**URL:** <https://discourse.julialang.org/t/does-stdlib-network-sockets-use-only-first-thread/123027>\
**Category:** General Usage\
**Tags:** networking, multithreading\
**Created:** [November 24, 2024, 9:33pm UTC](https://discourse.julialang.org/t/does-stdlib-network-sockets-use-only-first-thread/123027 "2024-11-24T21:33:18Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![Pedro](https://avatars.discourse-cdn.com/v4/letter/p/919ad9/32.png) [@Pedro](https://discourse.julialang.org/u/Pedro)\
**Post date:** [November 24, 2024, 9:33pm UTC](https://discourse.julialang.org/t/does-stdlib-network-sockets-use-only-first-thread/123027/1 "2024-11-24T21:33:18Z")

</div>

I am writing a multi-threaded applications with a GUI (CImGui.jl) and a network sockets (Base.Sockets) to handle low-latency data stream over local network via UDP.

I have a few independent threads to handle data processing and networking. First `UDPSocket` (source of data) and `recv` calls in one thread, and second `UDPSocket` (sink for processed data) and `send` calls in another thread. Data exchange between threads is done via `Channel`.

After various test why the output network stream lags, I found two cases:

1. When I spawn and pin function that handles GUI to thread with `Threads.threadid() == 1`, the frequency of `send` call decreases noticeably, and the `Channel` that is the source of data for `send` calls saturates.
2. When I spawn and pin function that handles GUI to thread with `Threads.threadid() == 2`, the frequency of `send` calls is equal to the frequency of incoming data, and the `Channel` that is the source of data for `send` calls is almost always empty whenever I am checking.

So do functions from `Base.Sockets` somehow use only thread `Threads.threadid() == 1`? Is such behavior of program is expected? At this moment, I didn’t found any information related to this in documentation. I would appreciate if somebody could clarify or point the relevant documentation/source code.

I can try to reproduce it with MWE, if needed. 🙂

---

_[View the full topic](https://discourse.julialang.org/t/does-stdlib-network-sockets-use-only-first-thread/123027)._
