On Sat, 23 Mar 2019 12:47:42 GMT, Sönke Ludwig wrote:

The thread model for vibe.d is strictly single-threaded/compartmented, with the exception of the primitives in vibe.core.sync. Unfortunately, the API of std.concurrency is not thread-safe w.r.t. type annotations and simply allows to pass any values between threads, no matter if they are shared or thread-local.

The solution is to keep the web socket in the original thread and instead pass the messages to and from the web socket using something like std.concurrency.

For performance reasons, you could also have a look at [vibe.core.channel][1], which is a strongly typed alternative with more flexibility w.r.t. receivers and senders (not tied to a particular task or thread). If dynamic typing is needed, a tagged union (as implemented by the "taggedalgebraic" or "sumtype" DUB packages) provides a more efficient (no heap allocations) alternative to Variant, which is used by std.concurrency.

[1]: https://github.com/vibe-d/vibe-core/blob/master/source/vibe/core/channel.d#L26

I just tried using std.concurrency to send the websocket messages between the threads, but now the cpu usage jumped to 14% (from >1%). Why is it doing this?

Also, is it at all possible to be able to pass websockets between threads? It would be a much easier solution.

Thanks!