I was using instance initialization which allocated a new object.
My intention was this initialization would happen per-instance,
but all instances appear to share the same sub-object? That is,
f1.b and f2.b appear to point to a single object? Obviously I
moved the new into the initializer
On Tuesday, 4 June 2024 at 12:22:23 UTC, Eric P626 wrote:
I tried to find a solution on the internet, but could not find
anything, I stumble a lot on threads about Go or Rust language
even if I specify "d language" in my search.
Aside from the excellent answer already present, I wanted to
On Sunday, 2 June 2024 at 17:46:09 UTC, bauss wrote:
If anything you should use a thread pool that each handles a
set of sockets, instead of each thread being a single socket.
Yup, thread pool it is. I'm still fleshing out the data
structure which manages the incoming work presented to the
On Friday, 31 May 2024 at 16:59:08 UTC, Jonathan M Davis wrote:
Strictly speaking, unless you're dealing with a module or
static-level variable, the object is not in TLS. It's treated
as thread-local by the type system, and the type system will
assume that no other thread has access to it, but
On Friday, 31 May 2024 at 19:48:37 UTC, kdevel wrote:
Have you taken into consideration that each of the
(pre-spawned) threads
can call accept()? Your program may also accept in multiple
processes on the same socket. [1]
Yes, but I am planning on some global behavior--mostly concerning
I'm coding a server which takes TCP connections. I end up in the
main thread with .accept() which hands me a Socket. I'd like to
hand this off to a spawn()'ed thread to do the actual work.
Aliases to mutable thread-local data not allowed.
Is there some standard way to get something
On Monday, 27 May 2024 at 04:04:03 UTC, mw wrote:
Pls NOTE: it is
a `sharded` (meaning trunk-ed) NON-concurrent map,
not `shared` concurrent map.
Assuming I put it in shared memory, in what way is it not able to
be used concurrently? It seems to have the needed lock
operations?
Thanks,
On Sunday, 26 May 2024 at 20:00:50 UTC, Jonathan M Davis wrote:
No operation on an associative array is thread-safe. As such,
you should not be doing _any_ operation on a shared AA without
first locking a mutex to protect it. Then you need to cast away
shared to access or mutate it or do
The following code fails to compile; it appears from the error
message that the library's clear() function is not ready to act
on a shared AA?
synchronized class F {
private:
string[int] mydict;
public:
void clear() {
this.mydict.clear();
}
}
void
main()
{
auto f =
I was playing with parallel programming, and experienced
"undefined behavior" when storing into an Associative Array in
parallel. Guarding the assignments with a synchronized barrier
fixed it, of course. And obviously loading down your raw AA with
thread barriers would be foolish.
But this
On Sunday, 12 May 2024 at 22:03:21 UTC, Ferhat Kurtulmuş wrote:
https://dlang.org/phobos/std_container_slist.html
This is a stack, isn't it? LIFO?
Ahh yes. Then use dlist
Thank you. I read its source, and was curious so I wrote a small
performance measurement: put 10,000 things in a FIFO,
On Sunday, 12 May 2024 at 19:45:44 UTC, Ferhat Kurtulmuş wrote:
On Saturday, 11 May 2024 at 23:44:28 UTC, Andy Valencia wrote:
I need a FIFO for a work scheduler, and nothing suitable
jumped out at me.
...
https://dlang.org/phobos/std_container_slist.html
This is a stack, isn't it? LIFO?
I need a FIFO for a work scheduler, and nothing suitable jumped
out at me. I wrote the following, but as a newbie, would be
happy to receive any suggestions or observations. TIA!
/*
* fifo.d
* FIFO data structure
*/
module tiny.fifo;
import std.exception : enforce;
const uint GROWBY
On Friday, 10 May 2024 at 16:33:53 UTC, Nick Treleaven wrote:
Arrays evaluate to true in boolean conditions if their `.ptr`
field is non-null. This is bug-prone and I hope we can remove
this in the next edition.
...
A string literal's `.ptr` field is always non-null, because it
is
On Friday, 10 May 2024 at 03:07:43 UTC, Steven Schveighoffer
wrote:
Yes, we say that a type has "truthiness" if it can be used in a
condition (`while`, `if`, `assert`, etc).
So if I may ask for one more small clarification... WRT
"truthiness", I've observed that empty arrays are treated as
On Friday, 10 May 2024 at 00:40:01 UTC, Meta wrote:
Yes. The reason for this is that it avoids having to
essentially do the same check twice. If `in` returned a bool
instead of a pointer, after checking for whether the element
exists (which requires searching for the element in the
tst7.d(6): Error: cannot implicitly convert expression `e in
this.members` of type `bool*` to `bool`
tst7.d(15): Error: template instance `tst7.Foo!uint` error
instantiating
I'm getting this for this bit of source (trimmed from the bigger
code). I switched to this.members.get(e, false) and
On Tuesday, 7 May 2024 at 01:14:24 UTC, Steven Schveighoffer
wrote:
On Tuesday, 7 May 2024 at 00:10:27 UTC, Andy Valencia wrote:
I had a set of default error messages to go with error code
numbers, and did something along the lines of:
string[uint] error_text = [
400: "A message",
I had a set of default error messages to go with error code
numbers, and did something along the lines of:
string[uint] error_text = [
400: "A message",
401: "A different message"
];
and got "expression is not a constant"
I eventually found this discussion:
On Friday, 26 April 2024 at 13:25:34 UTC, Salih Dincer wrote:
You have a 5-item data tuples as Tuple(1, 2, 3, [1, 3], 5) and
implement the sum (total = 15) with the least codes using the
sum() function of the language you are coding...
My Python solution (function named dosum to avoid
On Wednesday, 17 April 2024 at 03:13:46 UTC, Liam McGillivray
wrote:
Is there a way I can replace "`TypeB`" in the function
parameters with another symbol, and then define that symbol to
accept `TypeB` as an argument, but also accept `TypeA` which
would get converted to `TypeB` using a
On Monday, 15 April 2024 at 08:05:25 UTC, Patrick Schluter wrote:
The setup of a memory mapped file is relatively costly. For
smaller files it is a net loss and read/write beats it hands
down.
Interestingly, this performance deficit is present even when run
against the largest conveniently
On Thursday, 11 April 2024 at 14:54:36 UTC, Steven Schveighoffer
wrote:
For a repeatable comparison, you should provide the code which
does 1MB reads.
With pleasure:
import std.stdio : writeln, File, stderr;
const uint BUFSIZE = 1024*1024;
private uint
countnl(File f)
{
uint res = 0;
I wrote a "count newlines" based on mapped files. It used about
twice the CPU of the version which just read 1 meg at a time. I
thought something was amiss (needless slice indirection or
something), so I wrote the code in C. It had the same CPU usage
as the D version. So...mapped files,
On Wednesday, 10 April 2024 at 20:41:56 UTC, Lettever wrote:
```
import std;
Nullable!int func() => 3;
void main() {
Nullable!int a = 3;
//works fine
Nullable!int b = func();
//does not compile
}
Why make func() Nullable? It just wants to give you an int,
right? Making it a
I wanted a lightweight and simpler CSV decoder. I won't post the
whole thing, but basically you instantiate one as:
struct Whatever {
...
}
...
f = File("path.csv", "r");
auto c = CSVreader!Whatever(f);
foreach (rec; c) { ...
CSVreader is, of course, templated:
struct
On Friday, 15 March 2024 at 00:11:11 UTC, Andy Valencia wrote:
(varargs & friends)
Which statement leads me to section 77.2 of "Programming in D",
and now I am deep into the mechanisms behind what you have very
kindly shared. Thank you once more.
As some fruits of my labors here, below is
On Thursday, 14 March 2024 at 23:13:51 UTC, Basile B. wrote:
...
However explicit instantiation can take whatever is known at
compile time, such as constant expressions or even certain
static variables. So that is rather called an `alias sequence`
in D.
Which statement leads me to section
On Thursday, 14 March 2024 at 18:05:59 UTC, H. S. Teoh wrote:
...
The best way to do multi-type varags in D is to use templates:
import std;
void myFunc(Args...)(Args args) {
Thank you. The first parenthetical list is of types, is it not?
I can't find anywhere which says
Can somebody give me a starting point for understanding varadic
functions? I know that we can declare them
int[] args...
and pick through whatever the caller provided. But if the caller
wants to pass two int's and a _string_? That declaration won't
permit it.
I've looked into the
On Monday, 11 March 2024 at 16:25:13 UTC, Jonathan M Davis wrote:
...
But what exactly static means varies based on the context.
Thank you for the list! But none of those appear to apply to a
function defined in the outermost scope of the module. Is static
accepted here--but has no actual
Leveraging my knowledge of C, I assumed a "static" function would
be hidden outside of its own source file. I can't find any
statement about the semantics of a static function in the
documentation, and in practice (ldc2 on Linux) it doesn't hide
the function?
file tst.d:
import std.stdio
On Monday, 4 March 2024 at 18:08:52 UTC, Andy Valencia wrote:
For any other newbie dlang voyagers, here's a version which
works as expected using the system memory allocator. On my
little i7 I get 1.48 secs wallclock with 5.26 CPU seconds.
...
Using a technique I found in a unit test in
On Monday, 4 March 2024 at 16:02:50 UTC, Andy Valencia wrote:
On Monday, 4 March 2024 at 03:42:48 UTC, Richard (Rikki) Andrew
Cattermole wrote:
... I still hope to be able to share memory between spawned
threads, and if it isn't a shared ref of a shared variable,
then what would it be? Do I
On Monday, 4 March 2024 at 03:42:48 UTC, Richard (Rikki) Andrew
Cattermole wrote:
A way to do this without spawning threads manually:
...
Thank you! Of course, a thread dispatch per atomic increment is
going to be s.l.o.w., so not surprising you had to trim the
iterations.
Bug I still
I tried a shared memory parallel increment. Yes, it's basically
a cache line thrasher, but I wanted to see what's involved in
shared memory programming. Even though I tried to follow all the
rules to make true shared memory (not thread local) it appears I
failed, as the wait loop at the end
36 matches
Mail list logo