I have tried to scope the Mutex, but the D code gets a little slower, I don't know why:

5,6d5
< import std.typecons: scoped;
< import std.traits: ReturnType;
19,22c17,19
<         ReturnType!(scoped!Mutex) mtx;
<         alias this = value;
<     }
<     // pragma(msg, Bucket.sizeof); // 52 bytes
---
        Mutex mtx;
        alias this = value;
    }
31c28
<             b = Bucket(uniform(0, 100), scoped!Mutex());
---
            b = Bucket(uniform(0, 100), new Mutex());
35c32
<         return buckets[index].value;
---
        return buckets[index];
70,76c67,68
<         //sink(text(buckets));
<         sink("[");
<         foreach (ref b; buckets) {
<             sink(text(b.value));
<             sink(" ");
<         }
<         sink("] ");
---
        sink(text(buckets));
        sink(" ");


(And as you see the "alias this" of Bucket partially stops working).

Bye,
bearophile

Reply via email to