Jump to page: 1 24  
Page
Thread overview
Shared - Another Thread
Oct 17, 2018
Stefan Koch
Oct 17, 2018
Stefan Koch
Oct 17, 2018
Stanislav Blinov
Oct 17, 2018
Stefan Koch
Oct 17, 2018
H. S. Teoh
Oct 17, 2018
Stanislav Blinov
Oct 17, 2018
Stefan Koch
Oct 17, 2018
H. S. Teoh
Oct 17, 2018
Stefan Koch
Oct 18, 2018
Patrick Schluter
Oct 18, 2018
Manu
Oct 18, 2018
Patrick Schluter
Oct 18, 2018
H. S. Teoh
[OT] Android
Oct 19, 2018
Joakim
Oct 19, 2018
H. S. Teoh
Oct 18, 2018
Erik van Velzen
Oct 18, 2018
Stanislav Blinov
Oct 18, 2018
Erik van Velzen
Oct 18, 2018
Stanislav Blinov
Oct 18, 2018
Paolo Invernizzi
Oct 19, 2018
Stanislav Blinov
Oct 20, 2018
Nicholas Wilson
Oct 20, 2018
Stanislav Blinov
Oct 20, 2018
Manu
Oct 20, 2018
Manu
Oct 20, 2018
Manu
Oct 20, 2018
Manu
Oct 19, 2018
Manu
Oct 20, 2018
Manu
Oct 18, 2018
Paolo Invernizzi
Oct 18, 2018
Vijay Nayar
Oct 18, 2018
Stanislav Blinov
Oct 18, 2018
Stanislav Blinov
Oct 18, 2018
Patrick Schluter
October 17, 2018
Hi,

reading the other shared thread  "shared - i need to be useful"(https://forum.dlang.org/thread/mailman.4299.1539629222.29801.digitalmars-d@puremagic.com)

let me to an important realisation concerning the reason shareding data across threads is so unintuitve and hard to get right.
The reason is that sharing in the real world has nothing to do with using something and the same time.
For example: If I share my flat with another person, that person, while occupying the same flat as me, cannot actually occupy the same space. It is physically impossible.

In other words sharing does not mean for multiple entities to own something it's rather about diving and managing the (temporary) ownership of fragments.

Therefore if ownership is unclear sharing is impossible.
The safest default for something shared with unclear ownership is to view it as untouchable/unreadble/unwritable until ownership is established.
October 17, 2018
On Wednesday, 17 October 2018 at 21:12:49 UTC, Stefan Koch wrote:
> [another person] cannot actually occupy the same space. It is physically impossible.

Actually, that's not quite true, If they were to try hard enough the result would be nuclear fusion, (I am guessing (I am not a phsysist)), in any case it would certainly mess up
 the state of everyone involved; which is exactly what happens win multi-threaded situations.
October 17, 2018
On Wednesday, 17 October 2018 at 21:29:07 UTC, Stefan Koch wrote:

> in any case it would certainly mess up
>  the state of everyone involved; which is exactly what happens win multi-threaded situations.

^ that is very true. And that is why:

- one must not keep shared and local data close together (e.g. within same cache line)
- one must not implicitly convert local data to shared data

Now, I perfectly understand what Manu wants: for `shared` to stop being a stupid keyword that nobody uses, and start bringing in value to the language. At the moment, the compiler happily allows you to write and read `shared` unhindered, which isn't useful at all. It also allows you to have weird things like shared destructors and postblits (which got extended to whole shared copy ctors in a DIP!). Latter is especially painful when attempting to define the whole type `shared`.
October 17, 2018
On Wednesday, 17 October 2018 at 21:40:35 UTC, Stanislav Blinov wrote:
> Now, I perfectly understand what Manu wants: for `shared` to stop being a stupid keyword that nobody uses, and start bringing in value to the language. At the moment, the compiler happily allows you to write and read `shared` unhindered, which isn't useful at all.

Very Good, that's what I wanted to happen :)
October 17, 2018
On Wed, Oct 17, 2018 at 09:29:07PM +0000, Stefan Koch via Digitalmars-d wrote:
> On Wednesday, 17 October 2018 at 21:12:49 UTC, Stefan Koch wrote:
> > [another person] cannot actually occupy the same space. It is physically impossible.
> 
> Actually, that's not quite true, If they were to try hard enough the result would be nuclear fusion, (I am guessing (I am not a phsysist)), in any case it would certainly mess up the state of everyone involved; which is exactly what happens win multi-threaded situations.

Nah, that's not even anywhere close to nuclear fusion.

The atoms which make up your body (and basically everything else) are mostly empty, with just a tiny speck of a nucleus, and a bunch of extremely tiny electrons zipping about. There's plenty of room for hundreds, if not thousands or millions, of persons to occupy the same space without any of the particles running into each other.

The problem, of course, is that they are also charged particles, and the electromagnetic forces that hold the atom in place would be greatly disturbed if two atoms were to occupy the same space simultaneously, leading to a (very fast and very violent) reorganization of nucleii and electrons.  What that looks like macroscopically, I can't say exactly, but certainly delicate structures like proteins, DNA, lipid layers, and such would cease to exist, their constituent particles being violently scattered every which way in the course of reorganizing themselves into new structures that would bring the electromagnetic forces back into balance (and that, in all likelihood, won't resemble anything close to their starting molecular structures).  Whatever the result may be, I'm pretty certain it would not have good consequences for the biological processes built upon said delicate structures. To say the least. :-D

Two threads trying to access the same memory location at the same time, by comparison, would tend to have much less drastic, though no less dire, consequences.  :-D  Program crashes and security holes aside, at least we aren't talking about the transistors in the CPU suddenly (and violently) rearranging themselves into an unrecognizable slag (possibly with accompanying loud noises and flying shrapnel).  Even the program structure would mostly remain intact, though of course, logical consistency would be compromised, and you know what Walter says about programs that continue bungling forwards after a false assertion -- the code might wind up doing arbitrary things it was never intended to do, while being perfectly convinced that it is doing exactly what it was told.

But nobody will be building a fusion engine out of race conditions anytime in the foreseeable future. :-D


T

-- 
All men are mortal. Socrates is mortal. Therefore all men are Socrates.
October 17, 2018
On Wednesday, 17 October 2018 at 21:55:48 UTC, H. S. Teoh wrote:

> But nobody will be building a fusion engine out of race conditions anytime in the foreseeable future. :-D

We should be so blessed...

October 17, 2018
On Wednesday, 17 October 2018 at 21:55:48 UTC, H. S. Teoh wrote:
>
> Nah, that's not even anywhere close to nuclear fusion.
>
> The atoms which make up your body (and basically everything else) are mostly empty, with just a tiny speck of a nucleus, and a bunch of extremely tiny electrons zipping about. There's plenty of room for hundreds, if not thousands or millions, of persons to occupy the same space without any of the particles running into each other.
>
> But nobody will be building a fusion engine out of race conditions anytime in the foreseeable future. :-D
>
>
> T

Now my analogy sounds silly.

It's still valid though.

If something might be used by someone else it's better not to touch it, unless one has confirmation it is not used by someone else.

This is what shared has to enforce.
October 17, 2018
On Wed, Oct 17, 2018 at 10:13:37PM +0000, Stefan Koch via Digitalmars-d wrote:
> On Wednesday, 17 October 2018 at 21:55:48 UTC, H. S. Teoh wrote:
[...]
> > But nobody will be building a fusion engine out of race conditions anytime in the foreseeable future. :-D
[...]
> Now my analogy sounds silly.

Silly or not, think of the (fictional) possibilities if we *could* build fusion engines out of race conditions!  We could power starships with a team of incompetent programmers.  It would revolutionize everything!


> It's still valid though.
> 
> If something might be used by someone else it's better not to touch it, unless one has confirmation it is not used by someone else.
> 
> This is what shared has to enforce.

Yes.  But how can the compiler statically verify this?  Because if it cannot be statically verified, then somewhere along the line we have to trust the programmer. Ergo, it's programming by convention, and we all know how effective that is.

But I'm not sure if it's possible for the compiler to verify it, unless the language itself has a well-defined concurrency model with well-defined semantics.  Otherwise the best you could do is to implement heuristics, which will either lead to holes in the type system, or to an overly-restrictive conservative type system that nobody will use.


T

-- 
An elephant: A mouse built to government specifications. -- Robert Heinlein
October 17, 2018
On Wednesday, 17 October 2018 at 22:56:26 UTC, H. S. Teoh wrote:
> On Wed, Oct 17, 2018 at 10:13:37PM +0000, Stefan Koch via Digitalmars-d wrote:
>> On Wednesday, 17 October 2018 at 21:55:48 UTC, H. S. Teoh wrote:
> [...]
>> > But nobody will be building a fusion engine out of race conditions anytime in the foreseeable future. :-D
> [...]
>
>
>> It's still valid though.
>> 
>> If something might be used by someone else it's better not to touch it, unless one has confirmation it is not used by someone else.
>> 
>> This is what shared has to enforce.
>
> Yes.  But how can the compiler statically verify this?  Because if it cannot be statically verified, then somewhere along the line we have to trust the programmer. Ergo, it's programming by convention, and we all know how effective that is.
>
> [.... or it will lead] to an overly-restrictive conservative type system that nobody will use.
>

I'd rather wear 5 virtual straight-jackets than spending the rest of my life trying to observe invisble races, and wearing a real one.

Stefan
October 18, 2018
On Wednesday, 17 October 2018 at 21:55:48 UTC, H. S. Teoh wrote:

> The problem, of course, is that they are also charged particles, and the electromagnetic forces that hold the atom in place would be greatly disturbed if two atoms were to occupy the same space simultaneously, leading to a (very fast and very violent) reorganization of nucleii and electrons.  What that looks like macroscopically, I can't say exactly, but certainly delicate structures like proteins, DNA, lipid layers, and such would cease to exist, their constituent particles being violently scattered every which way in the course of reorganizing themselves into new structures that would bring the electromagnetic forces back into balance (and that, in all likelihood, won't resemble anything close to their starting molecular structures).  Whatever the result may be, I'm pretty certain it would not have good consequences for the biological processes built upon said delicate structures. To say the least. :-D

Even worst than that: conversion to/from E is involved in the process! :-P


« First   ‹ Prev
1 2 3 4