Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
D (programming language)
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
====Concurrency==== Concurrency is fully implemented in the library, and it does not require support from the compiler. Alternative implementations and methodologies of writing concurrent code are possible. The use of D typing system does help ensure memory safety. <syntaxhighlight lang="D"> import std.stdio, std.concurrency, std.variant; void foo() { bool cont = true; while (cont) { receive( // Delegates are used to match the message type. (int msg) => writeln("int received: ", msg), (Tid sender) { cont = false; sender.send(-1); }, (Variant v) => writeln("huh?") // Variant matches any type ); } } void main() { auto tid = spawn(&foo); // spawn a new thread running foo() foreach (i; 0 .. 10) tid.send(i); // send some integers tid.send(1.0f); // send a float tid.send("hello"); // send a string tid.send(thisTid); // send a struct (Tid) receive((int x) => writeln("Main thread received message: ", x)); } </syntaxhighlight>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)