How to kill whole application if child thread raises an exception?

2016-10-26 Thread dm via Digitalmars-d-learn

Thanks all.
I gues I must rewrote my app to send exeptions to other threads, 
use non blocking io, etc, etc.


Re: Unresolved Symbols in a nanovg Library

2016-10-26 Thread Jason C. Wells via Digitalmars-d-learn
I have a nice screen shot of the nanovg demo running. The old 
xeyes is a nice touch. I was excited to post the photo here but 
it looks like I cannot. I can tell by the animations that this 
will be precisely what I need to animate svg based 
instrumentation.


I ended up making one more static library for iv\vfs. I also 
ended up editing iv\vfs\package.d to comment out the reference to 
arcs. I was getting tired of following the missing symbols down 
the rabbit hole.


The ModuleInfoZ missing symbols were due to the package.d files 
in every case. I'll have to read up on those a bit more.


Oh and, as the end user, that demo has me all impressed. :)

Regards,
Jason C. Wells


Re: Unresolved Symbols in a nanovg Library

2016-10-26 Thread ketmar via Digitalmars-d-learn
On Thursday, 27 October 2016 at 02:12:34 UTC, Jason C. Wells 
wrote:

I have no idea where this ModuleInfoZ thing is coming from.


as Adam said, it means that it imports some module, and you 
didn't passed it to dmd. in this case, it is iv.nanovg.oui 
package (this is Blender-like GUI controls -- not a full GUI 
package, just GUI controls and some simple things). example is 
using that to draw OUI window to impress the end user. ;-)



How do I fix the missing ModuleInfoZ symbol?


just add everything from iv/nanovg/oui to dmd invocation.

BTW, I am not ignoring you guys when I haven't used rdmd ( I 
tried briefly but got stuck) or specifying all *.d files on the 
command line (did that with some success). My learning process 
is very organic and trial and error.


there is nothing wrong in that, of course. i keep telling about 
rdmd only 'cause it is easier to get at least *something* with 
it. but you'll eventually get it working with dmd too, and this 
is harder, but better way if you want to really grok the things. 
;-)


Re: Unresolved Symbols in a nanovg Library

2016-10-26 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 27 October 2016 at 02:18:26 UTC, Jason C. Wells 
wrote:

My learning process is very organic and trial and error.


yeah, that's us too :) With time, knowing all the details is 
better - you'll learn a lot though the start can be slower.


I usually keep my code simple, but there's a few fancy tricks 
mixed in too (like lazy imports or speculative modules...) so 
sometimes it is harder than you'd expect.


Also, my "package" is more just a collection of independent 
modules you can add to your project and hack on than something 
intended to be compiled separately. So you're kinda going against 
the grain... but it is educational and you can make it work!




Re: Unresolved Symbols in a nanovg Library

2016-10-26 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 27 October 2016 at 02:12:34 UTC, Jason C. Wells 
wrote:

 Error 42: Symbol Undefined _D2iv6nanovg3oui12__ModuleInfoZ


That means some module was imported but not compiled. You can run 
the `ddemangle` program that comes with dmd to translate it (or 
you'll get used to just reading it by eyeball - the pattern is 
_Dxyyy, repeated. The x is a number saying how long the next name 
is, and the yyy is the next part of the name. So 2iv6nanovg 
becomes iv.nanovg).


That means the iv.nanovg.oui was imported somewhere but not 
compiled in. The example surely uses it. ModuleInfo is 
auto-generated by the compiler for each module.


I am quite surprised that arsd is looking for 
iv\vfs\_something_.


ketmar and I semi-collaborate... our stuff is independent, but we 
know a number of more advanced tricks to selectively import if a 
file is available on the system.


So my jpeg.d (which was actually primarily authored by ketmar, 
well, he ported a C library and put an interface on top, then 
merged with my old jpg.d) will see if iv.vfs is available on the 
file system, and if it is, it will import it.


That works well if you just download a few files at a time (which 
is how I generally distribute my libs, I say "download file.d and 
other.d"), but if you downloaded *everything*, it will see it is 
there and try to show additional features.


But since you aren't compiling everything you have available, it 
sees it is there...but it isn't all built.




Re: Unresolved Symbols in a nanovg Library

2016-10-26 Thread Jason C. Wells via Digitalmars-d-learn
BTW, I am not ignoring you guys when I haven't used rdmd ( I 
tried briefly but got stuck) or specifying all *.d files on the 
command line (did that with some success). My learning process is 
very organic and trial and error.


I appreciate what you are doing for me. Thanks for the invite to 
chat on irc. I don't have an urgent need so I'll post here. Maybe 
other noobs will make use of this.


Re: Unresolved Symbols in a nanovg Library

2016-10-26 Thread Jason C. Wells via Digitalmars-d-learn
Adding iv\stb\ttf.d cleared up most of the remaining linker 
errors.


While compiling iv\nanovg_demo\example.d I am left with:

bin\example.obj(example)
 Error 42: Symbol Undefined _D2iv6nanovg3oui12__ModuleInfoZ

bin\example.obj(example)
 Error 42: Symbol Undefined _D2iv6nanovg12__ModuleInfoZ

..\..\..\lib\libarsd.lib(jpeg)
 Error 42: Symbol Undefined _D2iv3vfs12__ModuleInfoZ

I have no idea where this ModuleInfoZ thing is coming from. I 
searched the sources for the string "ModuleInfoZ" but that string 
appears only in obj/def files. I suppose that the compile/linker 
adds this symbol to object files.


How do I fix the missing ModuleInfoZ symbol?

I am quite surprised that arsd is looking for iv\vfs\_something_.

I should mention that I have been "picky" about which files I 
included on the dmd command line.


Re: Unresolved Symbols in a nanovg Library

2016-10-26 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 27 October 2016 at 01:48:54 UTC, Jason C. Wells 
wrote:
arsd has ttf.d and stb_truetype.d. Comments in stb_truetype.d 
say use ttf.d instead.


My ttf.d is just version 1.2 of stb_truetype.d basically... the 
two files are very similar and should be generally compatible.


ketmar's ttf.d I think is about 95% the same (we both ported the 
same C library), but slightly different, including a different 
module name... so you should be able to compile in both my ttf.d 
and his ttf.d at the same time.


Though I betcha his alone will be fine, or mine alone might be 
fine if you change the import statement (use `import arsd.ttf;` 
rather than `import iv.stb.ttf;`, the rest are probably 
compatible.)




Re: Unresolved Symbols in a nanovg Library

2016-10-26 Thread ketmar via Digitalmars-d-learn
On Thursday, 27 October 2016 at 01:48:54 UTC, Jason C. Wells 
wrote:
I'm not sure I fully understand name mangling, but it looks 
like nanovg wants to use iv\stb\ttf.d from it's own source 
tree. But Ketmar said "p.s. you will also need stb_ttf port, 
arsd repo has it under the name "ttf.d"."


So which ttf.d should I use? Does it matter?


it really doesn't, but you should have only one. ;-) the idea is 
that nanovg tries to import several stb_truetype ports (including 
iv.freetype bindings) and will use the first one that imported 
successfully. it is, again, works nice with rdmd and full IV 
repo, but may fail if you'll pass Adam's ttf.d in command line, 
while there is iv.ttf accessible on the disk. in this case 
importing of iv.ttf will succeed, but the code will be generated 
for arsd.ttf. oops.


Perhaps Ketmar intended to remove his copy of ttf.d from his 
repo?


quite the contrary. ;-) if anything resides in IV, then it is 
preferred thing to use with any IV modules. i strongly suggest 
you to move to rdmd, it can do most of such things for you. ;-)


as for nanovg, the preferred is iv.freetype, actually. then 
iv.ttf, then arsd.ttf. btw, you can find me on IRC channel (and 
Adam too), and ask your questions in real-time (well, if we are 
online ;-).


Unresolved Symbols in a nanovg Library

2016-10-26 Thread Jason C. Wells via Digitalmars-d-learn
I've gone about building static libraries for nanovg and arsd. 
(I'm feeling pretty good about what I've learned in the last 
couple days, so I gave it a whirl.)


arsd has ttf.d and stb_truetype.d. Comments in stb_truetype.d say 
use ttf.d instead.


nanovg has a ttf.d also.

There are three ttf.d's to choose from.

nanovg has linker errors:
..\..\..\lib\libnanovg.lib(nanovg)
 Error 42: Symbol Undefined 
_D2iv3stb3ttf25stbtt_ScaleForPixelHeightFPxS2iv3stb3ttf14stbtt_fontinfofZf


I'm not sure I fully understand name mangling, but it looks like 
nanovg wants to use iv\stb\ttf.d from it's own source tree. But 
Ketmar said "p.s. you will also need stb_ttf port, arsd repo has 
it under the name "ttf.d"."


So which ttf.d should I use? Does it matter?

I've gained enough confidence in the last couple days to go ahead 
and use trial and error to sort this out. I thought I'd let you 
guys chime in.


Perhaps Ketmar intended to remove his copy of ttf.d from his repo?

Regards,
Jason C. Wells


Re: [vibe.d] showing images

2016-10-26 Thread Nicholas Wilson via Digitalmars-d-learn
On Wednesday, 26 October 2016 at 18:39:00 UTC, Rene Zwanenburg 
wrote:
On Wednesday, 26 October 2016 at 12:42:09 UTC, Nicholas Wilson 
wrote:

[...]


You need to make the images accessible over HTTP. Note the use 
of staticFileServer in the following example:


http://vibed.org/docs#http-routing


Thanks. I ended up getting rid if the class and using the get and 
post method on the router.


Re: [vibe.d] showing images

2016-10-26 Thread Karabuta via Digitalmars-d-learn
On Wednesday, 26 October 2016 at 12:42:09 UTC, Nicholas Wilson 
wrote:

doctype html
html
body
-foreach(s; images)
// it doesn't seem to like #{s} or !{s}
img(src=s)

[...]


Inherit from Web interface?


Re: test for equality of the content of two AA

2016-10-26 Thread Ali Çehreli via Digitalmars-d-learn

On 10/26/2016 08:03 AM, Paolo Invernizzi wrote:

As the subject states, what is the best idiomatic way for doing that?

Thanks in advance
/Paolo


If you mean D's AAs, then that is already implemented:

  void main() {
auto a = [ "hello" : 1, "world" : 2 ];
auto b = [ "world" : 2, "hello" : 1 ];
assert(a == b);
}

The source makes sense:

  https://github.com/dlang/druntime/blob/master/src/rt/aaA.d#L615

* First check that the lengths are equal

* Then check each element

The last step is already fast without needing any other data structure 
(e.g. one may imagine a sorted array) because hash table lookup is O(1) 
and there are N elements that needs to be processed (i.e. compared), so 
the whole operation must be O(N).


If the equality comparison is very frequent, then a hash table that 
maintains a hash of all keys and values can be used, which would be 
O(1). (As far as I know D's AAs don't have such a feature.) This would 
make the comparison of non-equal tables O(1) but if this overall hash 
were equal between two tables, one would still have to compare every 
element to be sure, which would be O(N).


Ali



Re: [vibe.d] showing images

2016-10-26 Thread Rene Zwanenburg via Digitalmars-d-learn
On Wednesday, 26 October 2016 at 12:42:09 UTC, Nicholas Wilson 
wrote:

doctype html
html
body
-foreach(s; images)
// it doesn't seem to like #{s} or !{s}
img(src=s)

--
shared static this()
{
auto router = new URLRouter;
router.registerWebInterface(new CamController);

auto settings = new HTTPServerSettings;
settings.port = 8081;
settings.bindAddresses = ["::1", "127.0.0.1"];
listenHTTP(settings, router);


}
class Controller
{
void index(HTTPServerRequest req, HTTPServerResponse res)
{
auto images = 
dirEntries("public/images",SpanMode.breadth)

.map!(f=> f.name).array;
writeln(images); // ["public/images/testprog.jpg"]
res.render!("index.dt",images);
}
 }

What am I missing? I just get a 404 for the image.


You need to make the images accessible over HTTP. Note the use of 
staticFileServer in the following example:


http://vibed.org/docs#http-routing


Re: Map type to class instance at compile-time

2016-10-26 Thread Ali Çehreli via Digitalmars-d-learn

On 10/26/2016 10:48 AM, pontius wrote:
> Apologies for the long post or stupid questions, I only started to learn
> D today.

Looking at what you've achieved in one day, we really need you! :)

> I have a use case where various types (A, B, C) need to be associated
> with instances of different classes (ManagerA, ManagerB, ManagerC). A
> certain object (globalManager) should redirect operations on those types
> to their respective managers at compile-time. I intend to use it in the
> following way:
>
> class GlobalManager(TypeToManagerMapping) {
> public void process(T)(T t) {
> // Must be resolved at compile-time
> TypeToManagerMapping.getManagerForType(T).process(t);
> }
> }
>
> // All these types can be completely unrelated, i.e. no base classes
> struct A {}
> alias ManagerA = DefaultManager!(A)
> struct B {}
> alias ManagerB = DefaultManager!(B)
> struct C {}
> alias ManagerC = SomeCustomManager;
>
> // Calls to globalManager should be redirected to these at compile-time
> auto mgrA = new ManagerA();
> auto mgrB = new ManagerB();
> auto mgrC = new ManagerC();
>
> // This is my problem, see below
> alias TypeToManagerMapping = ...;
>
> // Pass the mapping as a template parameter so that it can be resolved
> at compile-time
> auto globalManager = new GlobalManager!(TypeToManagerMapping)();
>
> // The following is the module user's code.
> // The user may not be aware of mgrA, mgrB, etc, only of globalManager
>
> A a = A();
> B b = B();
> C c = C();
>
> // Redirection to managers in the following operations
> // must be resolved at compile-time
>
> // Should turn into mgrA.process(a), etc
> globalManager.process(a);
> globalManager.process(b);
> globalManager.process(c);

void report(M, T)() {
import std.stdio : writefln;
writefln("%s is managing an object of %s", M.stringof, T.stringof);
}

class DefaultManager(T) {
void manage(T t) {
report!(typeof(this), T);
}
}

class SomeCustomManager {
void manage(C c) {
report!(SomeCustomManager, C);
}
}

struct A {}
alias ManagerA = DefaultManager!(A);
struct B {}
alias ManagerB = DefaultManager!(B);
struct C {}
alias ManagerC = SomeCustomManager;

/*/ You can use this:

alias TypeToManagerMapping = AliasSeq!(A, ManagerA,
   B, ManagerB,
   C, ManagerC);
 However, if you already have symbolic mapping from T to ManagerT, you 
can use string mixins as well

*/
template ManagerRegistrationFor(T) {
// Just a couple of convenience functions
string managerType() { return "Manager" ~ T.stringof; }
string managerName() { return "mng" ~ T.stringof; }

// This is the manager object
mixin(managerType() ~ ' ' ~ managerName() ~ ';');

// This is the initialization of it
static this() {
mixin(managerName() ~ `= new ` ~ managerType() ~ ';');
}

void manage(T obj) {
// Dispatches to the manager
mixin(managerName() ~ ".manage(obj);");
}
}

struct GlobalManager {
void process(T)(T t) {
manage(t);
}
}

GlobalManager globalManager;

mixin ManagerRegistrationFor!A;
mixin ManagerRegistrationFor!B;
mixin ManagerRegistrationFor!C;

/* The above could be specified with an AliasSeq (uncompiled):

alias ManagedTypes = AliasSeq!(A, B, C);

This loop can be inside a template like RegisterManagedTypes

foreach (T; ManagedTypes) {
mixin ManagerRegistrationFor!T;
}

And then:

mixin RegisterManagedTypes;

*/

void main() {
A a = A();
B b = B();
C c = C();
globalManager.process(a);
globalManager.process(b);
globalManager.process(c);
}

There are different approaches but I think the solution above achieves 
what you want:


DefaultManager!(A) is managing an object of A
DefaultManager!(B) is managing an object of B
SomeCustomManager is managing an object of C

Ali



Map type to class instance at compile-time

2016-10-26 Thread pontius via Digitalmars-d-learn
Apologies for the long post or stupid questions, I only started 
to learn D today.
I have a use case where various types (A, B, C) need to be 
associated with instances of different classes (ManagerA, 
ManagerB, ManagerC). A certain object (globalManager) should 
redirect operations on those types to their respective managers 
at compile-time. I intend to use it in the following way:


class GlobalManager(TypeToManagerMapping) {
public void process(T)(T t) {
// Must be resolved at compile-time
TypeToManagerMapping.getManagerForType(T).process(t);
}
}

// All these types can be completely unrelated, i.e. no base 
classes

struct A {}
alias ManagerA = DefaultManager!(A)
struct B {}
alias ManagerB = DefaultManager!(B)
struct C {}
alias ManagerC = SomeCustomManager;

// Calls to globalManager should be redirected to these at 
compile-time

auto mgrA = new ManagerA();
auto mgrB = new ManagerB();
auto mgrC = new ManagerC();

// This is my problem, see below
alias TypeToManagerMapping = ...;

// Pass the mapping as a template parameter so that it can be 
resolved at compile-time

auto globalManager = new GlobalManager!(TypeToManagerMapping)();

// The following is the module user's code.
// The user may not be aware of mgrA, mgrB, etc, only of 
globalManager


A a = A();
B b = B();
C c = C();

// Redirection to managers in the following operations
// must be resolved at compile-time

// Should turn into mgrA.process(a), etc
globalManager.process(a);
globalManager.process(b);
globalManager.process(c);

So, I need to map a type (e.g. A) to an instance (e.g. mgrA). I 
have managed to implement a compile-time map from type to value 
(by the way, how do I get rid of TValue argument in 
TypeValuePair? it can be deduced, but I failed to get it working 
with an eponymous template):


struct TypeValuePair(TKey_, TValue, TValue value_) {
alias TKey = TKey_;
static const TValue value = value_;
}

struct StaticMap(THead, Args...) {
template get(T) {
static if (Args.length < 0) {
static assert(false, "StaticMap does not contain this 
key");
} else static if (is(T == THead.TKey)) {
alias get = THead.value;
} else {
alias get = StaticMap!(Args).get!(T);
}
}
}

This works nicely for mapping types to literal values:

alias TypeMap = StaticMap!(
TypeValuePair!(string, string, "a string"),
TypeValuePair!(int, string, "an int"),
TypeValuePair!(bool, string, "a bool")
);
writeln(TypeMap.get!(int));

But fails with "variable cannot be read at compile-time" when I 
try to pass a class instance in there:


alias TypeMap = StaticMap!(
TypeValuePair!(A, ManagerA, mgrA)
);
TypeMap.get!(A).process(a);

So, how do I resolve type-to-instance mapping at compile-time so 
that my user only needs to call globalManager and not know 
anything about individual managers?


I could easily do this with typeid() calls, but the solution must 
be purely compile-time (for learning purposes; let's say my code 
is performance-critical and the lookup would take considerable 
amount of time).


test for equality of the content of two AA

2016-10-26 Thread Paolo Invernizzi via Digitalmars-d-learn
As the subject states, what is the best idiomatic way for doing 
that?


Thanks in advance
/Paolo


Re: How to kill whole application if child thread raises an exception?

2016-10-26 Thread Kagamin via Digitalmars-d-learn

On Wednesday, 26 October 2016 at 10:03:30 UTC, dm wrote:
Why so strange default behavior do not kill other threads in 
case some of threads raise exception?

But thanks anyway.


AFAIK, on posix you should join the child thread, and when you 
do, the stored exception is rethrown in the joining thread.


Re: How to kill whole application if child thread raises an exception?

2016-10-26 Thread Adam D. Ruppe via Digitalmars-d-learn

On Wednesday, 26 October 2016 at 08:42:02 UTC, dm wrote:

I want to kill all my threads if it is unhandled exception.
How can I do that?


The spawnLinked function might help:

http://dpldocs.info/experimental-docs/std.concurrency.spawnLinked.html

http://dlang.org/phobos/std_concurrency.html#spawnLinked

" This new thread is linked to the calling thread so that if 
either it or the calling thread terminates a LinkTerminated 
message will be sent to the other, causing a LinkTerminated 
exception to be thrown on receive()."



At least that sounds basically right.


Re: [vibe.d] showing images

2016-10-26 Thread Nicholas Wilson via Digitalmars-d-learn

On Wednesday, 26 October 2016 at 12:57:24 UTC, wobbles wrote:
On Wednesday, 26 October 2016 at 12:42:09 UTC, Nicholas Wilson 
wrote:

[...]


When you get the 404, do you see the contents of 
'writeln(images);' in your terminal?


yes.

the 404 is only for the image the page still renders fine, but 
the image is replaced by the missing image image.


Re: [vibe.d] showing images

2016-10-26 Thread wobbles via Digitalmars-d-learn
On Wednesday, 26 October 2016 at 12:42:09 UTC, Nicholas Wilson 
wrote:

[...]


When you get the 404, do you see the contents of 
'writeln(images);' in your terminal?


[vibe.d] showing images

2016-10-26 Thread Nicholas Wilson via Digitalmars-d-learn

doctype html
html
body
-foreach(s; images)
// it doesn't seem to like #{s} or !{s}
img(src=s)

--
shared static this()
{
auto router = new URLRouter;
router.registerWebInterface(new CamController);

auto settings = new HTTPServerSettings;
settings.port = 8081;
settings.bindAddresses = ["::1", "127.0.0.1"];
listenHTTP(settings, router);


}
class Controller
{
void index(HTTPServerRequest req, HTTPServerResponse res)
{
auto images = dirEntries("public/images",SpanMode.breadth)
.map!(f=> f.name).array;
writeln(images); // ["public/images/testprog.jpg"]
res.render!("index.dt",images);
}
 }

What am I missing? I just get a 404 for the image.


Re: Neural Networks / ML Libraries for D

2016-10-26 Thread Ilya Yaroshenko via Digitalmars-d-learn

On Tuesday, 25 October 2016 at 13:56:45 UTC, Saurabh Das wrote:
On Tuesday, 25 October 2016 at 11:55:27 UTC, maarten van damme 
wrote:
There is mir https://github.com/libmir/mir which is geared 
towards machine learning, I don't know if it has anything 
about neural networks, I've yet to use it. If you're only 
interested in neural networks, I've used FANN (a C library) 
together with D and it worked very well.


2016-10-25 13:17 GMT+02:00 Saurabh Das via Digitalmars-d-learn 
< digitalmars-d-learn@puremagic.com>:



Hello,

Are there any good ML libraries for D? In particular, looking 
for a neural network library currently. Any leads would be 
appreciated.


Thanks,
Saurabh


I saw mir but it didn't seem to have anything for NNs. I'll 
give FANN a try.


https://github.com/ljubobratovicrelja/mir.experimental.model.rbf


Re: How to kill whole application if child thread raises an exception?

2016-10-26 Thread Paolo Invernizzi via Digitalmars-d-learn

On Wednesday, 26 October 2016 at 08:42:02 UTC, dm wrote:

Hi. I tried code below:

import std.concurrency;
import std.stdio;

void func()
{
throw new Exception("I'm an exception");
}

void main()
{
auto tID = spawn();
foreach(line; stdin.byLine)
send(tID, "");
}

I expect my application will die immediatly, but main thread 
still running and I don't see any errors.

I want to kill all my threads if it is unhandled exception.
How can I do that?


You need to link the threads, and at least one receive after the 
child thread has implicitly sent the exception to the main thread:


import std.concurrency;
import std.stdio;

---
void func()
{
throw new Exception("I'm an exception");
}

void main()
{
auto tID = spawnLinked();
receive((int dummy){});
}

---
/Paolo


Re: Avoiding GC

2016-10-26 Thread Edwin van Leeuwen via Digitalmars-d-learn

On Wednesday, 26 October 2016 at 08:18:07 UTC, hardreset wrote:
Is there a page somewhere on how to program D without using the 
GC? How do I allocate / free structs / classes on the heap 
manually? New would be GCed memeory wouldnt it? Delete is being 
depreciated?


thanks.


There is the following:
https://wiki.dlang.org/Memory_Management


Re: How to kill whole application if child thread raises an exception?

2016-10-26 Thread dm via Digitalmars-d-learn
On Wednesday, 26 October 2016 at 10:09:05 UTC, rikki cattermole 
wrote:

If you throw an error it should crash the entire application.
But really you need to set up sync points within your 
application to allow it to die gracefully.


I tried throw new Error... But main thread still working.
Tried with dmd v2.071.2 and ldc2 0.17.2. OS - Linux.


Re: How to kill whole application if child thread raises an exception?

2016-10-26 Thread rikki cattermole via Digitalmars-d-learn

On 26/10/2016 11:03 PM, dm wrote:

On Wednesday, 26 October 2016 at 09:43:10 UTC, rikki cattermole wrote:

```D
void entryPoint(alias func)() {
try {
func();
} catch (Exception e) {
import std.stdio;
writeln(e.toString());
}
}

void main() {
auto tid = spawn(!someFunc);
// ...

}
```


Well... This code shows me:
object.Exception@thread.d(6): I'm an exception


But my main thread still working :(
Why so strange default behavior do not kill other threads in case some
of threads raise exception?
But thanks anyway.


If you throw an error it should crash the entire application.
But really you need to set up sync points within your application to 
allow it to die gracefully.


Re: How to kill whole application if child thread raises an exception?

2016-10-26 Thread dm via Digitalmars-d-learn
On Wednesday, 26 October 2016 at 09:43:10 UTC, rikki cattermole 
wrote:

```D
void entryPoint(alias func)() {
try {
func();
} catch (Exception e) {
import std.stdio;
writeln(e.toString());
}
}

void main() {
auto tid = spawn(!someFunc);
// ...

}
```


Well... This code shows me:
object.Exception@thread.d(6): I'm an exception


But my main thread still working :(
Why so strange default behavior do not kill other threads in case 
some of threads raise exception?

But thanks anyway.


Re: How to kill whole application if child thread raises an exception?

2016-10-26 Thread Basile B. via Digitalmars-d-learn
On Wednesday, 26 October 2016 at 09:43:10 UTC, rikki cattermole 
wrote:
Basically when you spawn a thread giving the function, you pass 
it through another function which will catch any exceptions not 
normally caught.


Of course this really should be the default behavior but 
somebody else may be more of a help here.


And it is pseudo code, so please don't expect it to 100% work 
as I have written it.


```D
void entryPoint(alias func)() {
try {
func();
} catch (Exception e) {
import std.stdio;
writeln(e.toString());
}
}

void main() {
auto tid = spawn(!someFunc);
// ...

}
```


It doesn't return. It still have to be killed by hand. (at least 
on Linux)


Re: How to kill whole application if child thread raises an exception?

2016-10-26 Thread rikki cattermole via Digitalmars-d-learn
Basically when you spawn a thread giving the function, you pass it 
through another function which will catch any exceptions not normally 
caught.


Of course this really should be the default behavior but somebody else 
may be more of a help here.


And it is pseudo code, so please don't expect it to 100% work as I have 
written it.


```D
void entryPoint(alias func)() {
try {
func();
} catch (Exception e) {
import std.stdio;
writeln(e.toString());
}
}

void main() {
auto tid = spawn(!someFunc);
// ...

}
```


Re: How to kill whole application if child thread raises an exception?

2016-10-26 Thread dm via Digitalmars-d-learn
On Wednesday, 26 October 2016 at 08:53:13 UTC, rikki cattermole 
wrote:

Simple, handle the exceptions on each thread.


I don't want handle exceptions. I want my application crash with 
exception description. Can you change my code above to show how 
it can be made?


Re: How to kill whole application if child thread raises an exception?

2016-10-26 Thread rikki cattermole via Digitalmars-d-learn

On 26/10/2016 9:42 PM, dm wrote:

Hi. I tried code below:

import std.concurrency;
import std.stdio;

void func()
{
throw new Exception("I'm an exception");
}

void main()
{
auto tID = spawn();
foreach(line; stdin.byLine)
send(tID, "");
}

I expect my application will die immediatly, but main thread still
running and I don't see any errors.
I want to kill all my threads if it is unhandled exception.
How can I do that?


Simple, handle the exceptions on each thread.


How to kill whole application if child thread raises an exception?

2016-10-26 Thread dm via Digitalmars-d-learn

Hi. I tried code below:

import std.concurrency;
import std.stdio;

void func()
{
throw new Exception("I'm an exception");
}

void main()
{
auto tID = spawn();
foreach(line; stdin.byLine)
send(tID, "");
}

I expect my application will die immediatly, but main thread 
still running and I don't see any errors.

I want to kill all my threads if it is unhandled exception.
How can I do that?


Re: Avoiding GC

2016-10-26 Thread Andrea Fontana via Digitalmars-d-learn

On Wednesday, 26 October 2016 at 08:18:07 UTC, hardreset wrote:
Is there a page somewhere on how to program D without using the 
GC? How do I allocate / free structs / classes on the heap 
manually? New would be GCed memeory wouldnt it? Delete is being 
depreciated?


thanks.


Probably you want to read:
https://dlang.org/phobos/std_experimental_allocator.html

Anyway GC works really good for common software development.


Avoiding GC

2016-10-26 Thread hardreset via Digitalmars-d-learn
Is there a page somewhere on how to program D without using the 
GC? How do I allocate / free structs / classes on the heap 
manually? New would be GCed memeory wouldnt it? Delete is being 
depreciated?


thanks.


Re: Module Name Resolution

2016-10-26 Thread Jason C. Wells via Digitalmars-d-learn

On Wednesday, 26 October 2016 at 05:46:30 UTC, ketmar wrote:

this is a repository name. it is supposed to be named just 
"iv", and git names main directory by repository name if you 
are doing a simple clone. my bad, i should have made that clear.


Ok. That helps.