On Monday, 15 October 2018 at 20:53:32 UTC, Manu wrote:
On Mon, Oct 15, 2018 at 1:05 PM Peter Alexander via
Digitalmars-d <digitalmars-d@puremagic.com> wrote:
On Monday, 15 October 2018 at 18:46:45 UTC, Manu wrote:
1. A single producer, single consumer (SPSC) queue is
necessarily shared, but is only safe if there is one writing
thread and one reading thread. Is it ok if shared also
requires user discipline and/or runtime checks to ensure
correct usage?
I think you can model this differently... perhaps rather than a
single
object, it's a coupled pair.
That's a nice design.
Your swap function is plain broken; it doesn't do what the API
promises.
You can write all sorts of broken code, and this is a good
example of
just plain broken code.
If it is broken then why allow it? Why do we need to cast shared
away if they weren't atomic and why do we allow it if they are
atomic?
I understand that shared can't magically tell you when code is
thread safe or not. It does make sense to disallow almost
everything and require casts. I'm just not seeing the value of
allowing shared methods to access shared members if it isn't
thread safe. Make it require casts.