www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Unsafe, unchecked message-passing with std.concurrency

reply Elronnd <elronnd elronnd.net> writes:
Is there any way to do unsafe, unchecked message-passing using 
std.concurrency's API?  I want to be able to share mutable data 
without having to qualify it as shared.  It looks like the check 
happens in send(), before passing off data to _send(), which does 
no checking; but _send is private.  Is there any analogous 
functionality elsewhere in phobos--send_unchecked or similar?
Aug 27 2020
parent reply Simen =?UTF-8?B?S2rDpnLDpXM=?= <simen.kjaras gmail.com> writes:
On Thursday, 27 August 2020 at 08:39:49 UTC, Elronnd wrote:
 Is there any way to do unsafe, unchecked message-passing using 
 std.concurrency's API?  I want to be able to share mutable data 
 without having to qualify it as shared.  It looks like the 
 check happens in send(), before passing off data to _send(), 
 which does no checking; but _send is private.  Is there any 
 analogous functionality elsewhere in phobos--send_unchecked or 
 similar?
Since you're fine with unsafe, unchecked - why not just lie to the compiler? Cast the data to shared and send it on its merry way? -- Simen
Aug 27 2020
parent reply Elronnd <elronnd elronnd.net> writes:
On Thursday, 27 August 2020 at 08:46:31 UTC, Simen Kjærås wrote:
 Since you're fine with unsafe, unchecked - why not just lie to 
 the compiler? Cast the data to shared and send it on its merry 
 way?
It's bothersome and error-prone. I have to cast the data to shared. I also have to remember to receive a shared object on the other side (and if I forget, I won't get a compile error, stuff will just silently break). Once I've received it, I have to cast away the shared again if I want to be able to use the object for anything. I'll do that if I have to, (or write my message-passing library, or repurpose one from C), but would be nice if there were another solution.
Aug 27 2020
parent Petar Kirov [ZombineDev] <petar.p.kirov gmail.com> writes:
On Thursday, 27 August 2020 at 08:59:45 UTC, Elronnd wrote:
 On Thursday, 27 August 2020 at 08:46:31 UTC, Simen Kjærås wrote:
 Since you're fine with unsafe, unchecked - why not just lie to 
 the compiler? Cast the data to shared and send it on its merry 
 way?
It's bothersome and error-prone. I have to cast the data to shared. I also have to remember to receive a shared object on the other side (and if I forget, I won't get a compile error, stuff will just silently break). Once I've received it, I have to cast away the shared again if I want to be able to use the object for anything. I'll do that if I have to, (or write my message-passing library, or repurpose one from C), but would be nice if there were another solution.
The simplest solution is to write your own wrappers of `send` and `receive` and have them do the casting for you.
Aug 27 2020