DList - Various Comments/Questions
Chris Williams
yoreanon-chrisw at yahoo.co.jp
Thu Dec 13 18:33:31 PST 2012
Greetings,
I was attempting to use DList as a queue, for allowing data to be
processed among a group of threads.
The first problem, here, is of course that I can't synchronize on
a struct. This can be resolved easily enough by creating a second
object like:
Object lock = new Object();
While I do understand that most threading is meant to be done via
message passing, that's not really the best solution for all
applications. Much threading is done on containers, so having
them naturally able to be synchronized on would be useful for
many situations. Perhaps instead of implementing the containers
as structs or classes, it would be better to implement them as
templates, which can be dropped into a struct or a class,
depending on what the user needs?
I also notice that the compiler is unable to detect struct
initializers when I try to init my DList.
E.g.:
struct SomeData {
string a;
string b;
}
alias DList!(SomeData) SomeList;
SomeList queue;
static this() {
queue = SomeList([
{"Foo", "Bar"} // Compiler error
]);
}
I also noticed that this doesn't work either:
static this() {
SomeData curr;
curr = {"Foo", "Bar"}; // Compiler error
SomeList.insertBack(curr);
}
And then I'm also finding that it's not acting like I would
expect:
SomeData curr = {"Foo", "Bar"};
queue.insertBack(curr);
SomeData temp = queue.removeAny();
if (queue.empty()) {
writeln("I'm empty!");
}
else {
writeln("Whyyyyy?"); // This is what it prints
}
At the moment, it seems easier to write my own implementation,
which seems unfortunate, given how central to a language its
basic containers are.
More information about the Digitalmars-d
mailing list