haskell / haskell/network

Thread safety of Datagram send and receive

Open
#444 23 comments 0 reactions 1 assignee Claimed by @schmittlauch View on GitHub
Dominant language
Haskell
Stars
366
Forks
210
Avg merge
22h 38m
Merged PRs (30d)
5

Description

The package documentation claims that `send` and `receive` operations on the same socket are not thread safe:

> The proper programming model is that one Socket is handled by a single thread. If multiple threads use one Socket concurrently, unexpected things would happen. There is one exception for multiple threads vs a single Socket: one thread reads data from a Socket only and the other thread writes data to the Socket only.

In a [discussion on StackOverflow](https://stackoverflow.com/a/61049133/9198613) though the opinion was brought up that in POSIX, `send`, `sendTo`, `receive` and `receiveFrom` are defined as atomic operations, making them thread safe at least for Datagram sockets.

With this library mostly being a thin wrapper around the Berkeley sockets API: Are operations on the same Datagram socket atomic? If not, why?

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.