Re: Best Direction on Spawning Process Async

2015-09-16 Thread Ali Çehreli via Digitalmars-d-learn

On 09/15/2015 09:21 PM, Mike McKee wrote:

What's the best direction from...

http://dlang.org/phobos/std_process.html

...on spawning an async process and then peeking at it occasionally as
it runs, and then get notified when it finishes? In other words, what
std.process functions would you recommend I use? What I want to avoid is
a blocking state where the GUI freezes because it's waiting for the
process to complete.

For instance, imagine you are building a front end GUI (like GtkD) to a
command-line based antivirus scanner. You'll want to spawn the process,
show a progress bar, and as the command line returns status information,
you peek at it asynchronously and then update the progress bar (or
perhaps store virus detected info in a table), and then stop the
progress bar at 100% when the command process has finished.



Sounds like an easy task for std.concurrency:

import std.stdio;
import std.concurrency;
import core.thread;

struct Progress {
int percent;
}

struct Done {
}


void doWork() {
foreach (percent; 0 .. 100) {
Thread.sleep(100.msecs);
if (!(percent % 10)) {
ownerTid.send(Progress(percent));
}
}

ownerTid.send(Done());
}

void main() {
auto worker = spawn(&doWork);

bool done = false;
while (!done) {
bool received = false;

while (!received) {
received = receiveTimeout(
// Zero timeout is a non-blocking message check
0.msecs,
(Progress message) {
writefln("%s%%", message.percent);
},

(Done message) {
writeln("Woohoo!");
done = true;
});

if (!received) {
// This is where we can do more work
Thread.sleep(42.msecs);
write(". ");
stdout.flush();
}
}
}
}

Ali



Re: Initalizing complex array types or some other problem ;/

2015-09-16 Thread Andrea Fontana via Digitalmars-d-learn

On Wednesday, 16 September 2015 at 01:46:09 UTC, Prudence wrote:
In any case, Maybe you are not as smart as you think you are if 
you can't understand it? Maybe next time you shouldn't assume 
you are the oracle of all knowledge and if you can't understand 
it then it's bad/wrong.


In fact, it's quite simple to understand for anyone with half a 
brain.


Seriously. Don't guess. It's not that complex and it would take 
you 5 mins to understand if you wanted. No reason to try and 
through your ego in it.


"Prudence" seems not to fit well as nickname.



What kind of sorcery is that?

2015-09-16 Thread NX via Digitalmars-d-learn

import std.stdio;
void main()
{
Stuff!(Thing!float) s;
writeln(typeid(s.var));
writeln(typeid(s.var.varling));
writeln(typeid(s));
}
class Stuff(T)
{
T!int var;
}
class Thing(T)
{
T varling;
}


Re: What kind of sorcery is that?

2015-09-16 Thread John Colvin via Digitalmars-d-learn

On Wednesday, 16 September 2015 at 08:28:24 UTC, NX wrote:

import std.stdio;
void main()
{
Stuff!(Thing!float) s;
writeln(typeid(s.var));
writeln(typeid(s.var.varling));
writeln(typeid(s));
}
class Stuff(T)
{
T!int var;
}
class Thing(T)
{
T varling;
}


Filed a bug: https://issues.dlang.org/show_bug.cgi?id=15069


Why do abstract class functions require definitions?

2015-09-16 Thread FiveNights via Digitalmars-d-learn
Every so often I'll get a compiler error that isn't particularly 
clear on what's wrong and eventually I'll figure out that what's 
causing it is having a function in an abstract class somewhere 
that isn't defined:


abstract class SomeClass {
int someVariable;
void someFunction();
}
the solution is usually:
void someFunction(){}

Usually the abstract class is a converted interface, but it 
turned out that I needed to include a variable for it to work out 
and I just wasn't keen on remembering to put a mixin in each 
derived class.


I'm just wondering why I can't have an undefined function in an 
abstract class? I'd the compiler to say, "Hey, you forgot to put 
'someFunction()' in 'SomeDerrivedClass', go do something about 
that." when I end a function with a semi-colon in the base class 
and don't have it in the derrived. Everything just seems to break 
in cryptic ways unless I curly brace the function ending.


Re: Runtime error when calling a callback in a parallel Task

2015-09-16 Thread BBasile via Digitalmars-d-learn

On Tuesday, 15 September 2015 at 23:49:23 UTC, BBasile wrote:
Under Windows this works fine but under Linux I got a runtime 
error.


this could be reduced to :
[...]
If it can help to understand the problem, here is the unreducted 
case:


https://github.com/BBasile/Coedit/blob/master/cedast/src/ast.d#L343


Re: Why do abstract class functions require definitions?

2015-09-16 Thread Kagamin via Digitalmars-d-learn

declare as
abstract void someFunction();


Re: Re-named & Selective Imports

2015-09-16 Thread Kagamin via Digitalmars-d-learn
Well, arguably disjunctive combination doesn't make much sense 
here, because renamed import disambiguates it all enough, but 
makes it impossible to merge arbitrary namespaces ad hoc, a 
feature I missed several times.


Re: Why do abstract class functions require definitions?

2015-09-16 Thread Jacob Carlborg via Digitalmars-d-learn

On 2015-09-16 10:49, FiveNights wrote:

Every so often I'll get a compiler error that isn't particularly clear
on what's wrong and eventually I'll figure out that what's causing it is
having a function in an abstract class somewhere that isn't defined:

abstract class SomeClass {
 int someVariable;
 void someFunction();
}
the solution is usually:
void someFunction(){}

Usually the abstract class is a converted interface, but it turned out
that I needed to include a variable for it to work out and I just wasn't
keen on remembering to put a mixin in each derived class.

I'm just wondering why I can't have an undefined function in an abstract
class? I'd the compiler to say, "Hey, you forgot to put 'someFunction()'
in 'SomeDerrivedClass', go do something about that." when I end a
function with a semi-colon in the base class and don't have it in the
derrived. Everything just seems to break in cryptic ways unless I curly
brace the function ending.


I'm guessing you see a link error. The reason you see that instead of a 
compile error is because D supports separate compilation. Meaning that 
the method could be implemented in a different library that are resolved 
during link time.


As already answered in another post, the solution is to prefix the 
method declaration with "abstract".


--
/Jacob Carlborg


Re: Why do abstract class functions require definitions?

2015-09-16 Thread Marc Schütz via Digitalmars-d-learn
On Wednesday, 16 September 2015 at 09:31:25 UTC, Jacob Carlborg 
wrote:

On 2015-09-16 10:49, FiveNights wrote:
Every so often I'll get a compiler error that isn't 
particularly clear
on what's wrong and eventually I'll figure out that what's 
causing it is
having a function in an abstract class somewhere that isn't 
defined:


abstract class SomeClass {
 int someVariable;
 void someFunction();
}
the solution is usually:
void someFunction(){}

Usually the abstract class is a converted interface, but it 
turned out
that I needed to include a variable for it to work out and I 
just wasn't

keen on remembering to put a mixin in each derived class.

I'm just wondering why I can't have an undefined function in 
an abstract
class? I'd the compiler to say, "Hey, you forgot to put 
'someFunction()'
in 'SomeDerrivedClass', go do something about that." when I 
end a
function with a semi-colon in the base class and don't have it 
in the
derrived. Everything just seems to break in cryptic ways 
unless I curly

brace the function ending.


I'm guessing you see a link error. The reason you see that 
instead of a compile error is because D supports separate 
compilation. Meaning that the method could be implemented in a 
different library that are resolved during link time.


As already answered in another post, the solution is to prefix 
the method declaration with "abstract".


Wouldn't the following behaviour be more useful as a default?

abstract class Foo {
void bar1() { } // non-abstract, obviously
void bar2();// abstract, because it's in an 
abstract class

// (different from now)
extern void bar3(); // non-abstract, but defined 
externally

}


How do I change debug mode with dub?

2015-09-16 Thread Alex_Freeman via Digitalmars-d-learn
Hey all! I'm just wondering how to run dub with different debug 
versions, or running it with different versions generally? Is 
there also a way to have code behind multiple debug versions, or 
run more than one debug version at once?


Thanks!


Re: Final templated interface method not found

2015-09-16 Thread Andre via Digitalmars-d-learn

Thanks, it works like a charme.

Kind regards
André


Re: How do I change debug mode with dub?

2015-09-16 Thread Gary Willoughby via Digitalmars-d-learn
On Wednesday, 16 September 2015 at 10:42:13 UTC, Alex_Freeman 
wrote:
Hey all! I'm just wondering how to run dub with different debug 
versions, or running it with different versions generally? Is 
there also a way to have code behind multiple debug versions, 
or run more than one debug version at once?


Thanks!


There's lots of useful information here:
http://code.dlang.org/package-format?lang=json


"if sting in string"

2015-09-16 Thread smadus via Digitalmars-d-learn

Hello

Searching after hours, i give up and here is the question. ;)

I will make a programm, this searching all txt files on the 
system or the path from user and searching a user tiped term in 
this file.


http://dpaste.dzfl.pl/dec09a0f849c

The Problem is in the if() "line 17" i searching in 
std.algorithm, but i dont find a solution for my problem.


i hope, someone can help me.

I'm new on D and sorry for my bad english.

Happy Greetings

Shorty




Re: "if sting in string"

2015-09-16 Thread cym13 via Digitalmars-d-learn

On Wednesday, 16 September 2015 at 12:55:13 UTC, smadus wrote:

Hello

Searching after hours, i give up and here is the question. ;)

I will make a programm, this searching all txt files on the 
system or the path from user and searching a user tiped term in 
this file.


http://dpaste.dzfl.pl/dec09a0f849c

The Problem is in the if() "line 17" i searching in 
std.algorithm, but i dont find a solution for my problem.


i hope, someone can help me.

I'm new on D and sorry for my bad english.

Happy Greetings

Shorty


Turn it into either:

if (canFind(line, term)) {...

or

if (line.canFind(term)) {...

(they are equivalent)

This mistake seems odd, is D your first programming language?


Re: "if sting in string"

2015-09-16 Thread Rikki Cattermole via Digitalmars-d-learn

On 17/09/15 12:55 AM, smadus wrote:

Hello

Searching after hours, i give up and here is the question. ;)

I will make a programm, this searching all txt files on the system or
the path from user and searching a user tiped term in this file.

http://dpaste.dzfl.pl/dec09a0f849c

The Problem is in the if() "line 17" i searching in std.algorithm, but i
dont find a solution for my problem.

i hope, someone can help me.

I'm new on D and sorry for my bad english.

Happy Greetings

Shorty


Highly inefficient design in code, but lets ignore that.

You want std.string : indexOf.

if (line.indexOf(term) >= 0) {

If I remember correctly.



Re: "if sting in string"

2015-09-16 Thread smadus via Digitalmars-d-learn

A lot of thanks... i choose the (line.canFind(term)).

No is not my first language, Python was my first, but i dont 
coding a long time...




Re: "if sting in string"

2015-09-16 Thread John Colvin via Digitalmars-d-learn

On Wednesday, 16 September 2015 at 12:55:13 UTC, smadus wrote:

Hello

Searching after hours, i give up and here is the question. ;)

I will make a programm, this searching all txt files on the 
system or the path from user and searching a user tiped term in 
this file.


http://dpaste.dzfl.pl/dec09a0f849c

The Problem is in the if() "line 17" i searching in 
std.algorithm, but i dont find a solution for my problem.


i hope, someone can help me.

I'm new on D and sorry for my bad english.

Happy Greetings

Shorty


line 17 should probably be:

if(canFind(line, term)){

you had your first closing bracket in the wrong place. Also, 
canFind looks for the second argument inside the first argument.


Other notes:

There is no need to pass the arguments by ref, the data is not 
copied.


File has a member function called byLine that can be used like 
this:

foreach(line; actually_file.byLine())
//do something with the line
see http://dlang.org/phobos/std_stdio.html#.File.byLine

No need to chomp a line before using canFind on it.

What are you trying to write on line 18? datei isn't defined 
anywhere


Re: Another, is it a bug?

2015-09-16 Thread Meta via Digitalmars-d-learn
On Wednesday, 16 September 2015 at 03:48:59 UTC, Random D user 
wrote:
Yeah... I guess I was expecting it to overload across class 
boundaries. I mean there's already a member eat in base class 
and sub class can't override that since it's got different 
parameters, and it's a function (can't be variable), so the 
reasonable thing would be to overload it (which is why I tried 
override to see if it forces/hints overriding/overloading).
Instead it creates two ambiguous names of which only one has to 
be disambiguated to use which seems super error prone. IMO it 
should just be error/warning.


Given that, normally properties are just overloaded methods in 
D, it's pretty sad classes break this behavior/convention.


It's the exact same as in Java, and probably C# as well. I don't 
know if there's any OOP language that overloads methods between 
the base and super class.


https://ideone.com/En5JEc


Re: Another, is it a bug?

2015-09-16 Thread Kagamin via Digitalmars-d-learn

On Wednesday, 16 September 2015 at 13:18:51 UTC, Meta wrote:
It's the exact same as in Java, and probably C# as well. I 
don't know if there's any OOP language that overloads methods 
between the base and super class.


https://ideone.com/En5JEc


https://ideone.com/aIIrKM No, there's nothing like that in Java 
and C#.


any way to initialize an array of structs to void?

2015-09-16 Thread ref2401 via Digitalmars-d-learn

struct MyStruct {
@disable this();

this(int a, string b) {
this.a = a;
this.b = b;
}

int a;
string b;
}

I know there is a way to create one instance of `MyStruct` and 
initialize it to void.

  MyStruct s = void;
  s = MyStruct(5, "abcdef");

How can initialize an array of `MyStruct` instances to void?
  auto arr = new MyStruct[10]; // compile-time Error: default 
construction is disabled for type MyStruct.


Re: Another, is it a bug?

2015-09-16 Thread Meta via Digitalmars-d-learn

On Wednesday, 16 September 2015 at 14:08:11 UTC, Kagamin wrote:

On Wednesday, 16 September 2015 at 13:18:51 UTC, Meta wrote:
It's the exact same as in Java, and probably C# as well. I 
don't know if there's any OOP language that overloads methods 
between the base and super class.


https://ideone.com/En5JEc


https://ideone.com/aIIrKM No, there's nothing like that in Java 
and C#.


Oh, whoops, you're right; I forgot to extend Test. My mistake.


Re: any way to initialize an array of structs to void?

2015-09-16 Thread Meta via Digitalmars-d-learn

On Wednesday, 16 September 2015 at 14:45:06 UTC, ref2401 wrote:

struct MyStruct {
@disable this();

this(int a, string b) {
this.a = a;
this.b = b;
}

int a;
string b;
}

I know there is a way to create one instance of `MyStruct` and 
initialize it to void.

  MyStruct s = void;
  s = MyStruct(5, "abcdef");

How can initialize an array of `MyStruct` instances to void?
  auto arr = new MyStruct[10]; // compile-time Error: default 
construction is disabled for type MyStruct.


MyStruct[10] arr = void;

Don't do this with a dynamic array, though, as they work a bit 
differently from static arrays.


Re: No -v or -deps for gdc?

2015-09-16 Thread Atila Neves via Digitalmars-d-learn
On Tuesday, 15 September 2015 at 18:12:56 UTC, Johannes Pfau 
wrote:

Am Tue, 15 Sep 2015 12:19:34 +
schrieb Atila Neves :

gdmd supports those options but gdc doesn't. Is that likely to 
always be the case?


Atila


gdmd is just a wrapper around gdc. If something is supported by 
gdmd it must also be supported by gdc (the exact switch names 
might differ).


See: 
https://github.com/D-Programming-GDC/GDMD/blob/master/dmd-script


Seems like -v maps to -fd-verbose and -deps to -fdeps.


Ah cool, thanks!

Atila


Re: any way to initialize an array of structs to void?

2015-09-16 Thread ref2401 via Digitalmars-d-learn

On Wednesday, 16 September 2015 at 14:48:59 UTC, Meta wrote:

Don't do this with a dynamic array, though, as they work a bit 
differently from static arrays.


Unfortunately I have to deal with dynamic arrays.


Re: any way to initialize an array of structs to void?

2015-09-16 Thread Meta via Digitalmars-d-learn

On Wednesday, 16 September 2015 at 14:51:51 UTC, ref2401 wrote:

On Wednesday, 16 September 2015 at 14:48:59 UTC, Meta wrote:

Don't do this with a dynamic array, though, as they work a bit 
differently from static arrays.


Unfortunately I have to deal with dynamic arrays.


In that case, you can use std.array.uninitializedArray or 
std.array.minimallyInitializedArray as needed.


http://dlang.org/phobos/std_array.html#uninitializedArray
http://dlang.org/phobos/std_array.html#.minimallyInitializedArray


Re: any way to initialize an array of structs to void?

2015-09-16 Thread ref2401 via Digitalmars-d-learn

On Wednesday, 16 September 2015 at 14:57:49 UTC, Meta wrote:


In that case, you can use std.array.uninitializedArray or 
std.array.minimallyInitializedArray as needed.


http://dlang.org/phobos/std_array.html#uninitializedArray
http://dlang.org/phobos/std_array.html#.minimallyInitializedArray


Thanks)


Re: How do I change debug mode with dub?

2015-09-16 Thread Alex_Freeman via Digitalmars-d-learn
On Wednesday, 16 September 2015 at 12:04:38 UTC, Gary Willoughby 
wrote:
On Wednesday, 16 September 2015 at 10:42:13 UTC, Alex_Freeman 
wrote:
Hey all! I'm just wondering how to run dub with different 
debug versions, or running it with different versions 
generally? Is there also a way to have code behind multiple 
debug versions, or run more than one debug version at once?


Thanks!


There's lots of useful information here:
http://code.dlang.org/package-format?lang=json


Thanks for the link!

I got it working with adding
"debugVersions": ["whatever","I","want"]
to my dub.json file :)


Re: Creating a DLL with a ActiveX interface.

2015-09-16 Thread Taylor Hillegeist via Digitalmars-d-learn

On Monday, 14 September 2015 at 16:59:20 UTC, Adam D. Ruppe wrote:
On Monday, 14 September 2015 at 15:44:36 UTC, Taylor Hillegeist 
wrote:
So, Actually I am using NI LabVIEW to interact with my DLL. I 
imagine even getting hold of of that would troublesome or 
expensive.


Ah, all right. Here's a SO thing (followed up by email then


Fortunately I am working with Win7, And the below function seems 
to work beautifully.


export extern (Windows) void SayHello(Variant *Input_Variant)
{
string A = "HELLO WORLD!";
Input_Variant.CA_VariantSetCString(A.ptr);
}

My goal was to store variants in an associative array 
Variant[string] and use this as a portable interpreter returning 
the resulting Variant.


but that runs into some memory questions that I am not as savvy 
with.


1. Memory:
I need to manage memory from the dll. I can give the caller a 
pointer to manage, but I don't think that is visible from gc. 
There should be different associtive arrays for different objects 
in the caller. How do I manage this?


2. Threads:
I would like this to be as parallel as possible one objects call 
to its data should not hinder anothers.


I have seen on the Memory managment page 
http://wiki.dlang.org/Win32_DLLs_in_D  but I would like to know 
more.






Re: Best Direction on Spawning Process Async

2015-09-16 Thread Mike McKee via Digitalmars-d-learn

Beautiful, Ali. Took me a bit to read here...

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

...but I realized that receiveTimeout() was a std.concurrency 
class method.





Re: Best Direction on Spawning Process Async

2015-09-16 Thread Mike McKee via Digitalmars-d-learn
This really shows the beauty and simplicity of the D language 
compared to C++. Check this out in Qt/C++:


http://stackoverflow.com/questions/32593463/spawn-async-qprocess-from-dynamic-library-peek-output-until-done

...see how much nicer the D version is here that Ali did, versus 
the Qt/C++ technique.




Thrift

2015-09-16 Thread ddos via Digitalmars-d-learn
Looking for a RPC library, thrift looked promising, but i can't 
even compile the simple example given here 
https://thrift.apache.org/tutorial/d


to compile i've
1. copied the thrift/lib/d/src/thrift folder to my source 
directory
2. copied the generated sources ( tutorial and share folder ) 
into my source directory
3. compiling with dub and dmd 66 ( ive also tried 68 before with 
the same result )


dub.json: http://pastebin.com/pQSsCUAd
compiling errors: http://pastebin.com/qp02S1EW

please help if you know how to get a simple example with d & 
thrift running

thx, dominik


Re: Runtime error when calling a callback in a parallel Task

2015-09-16 Thread Ali Çehreli via Digitalmars-d-learn

On 09/15/2015 04:49 PM, BBasile wrote:

Under Windows this works fine but under Linux I got a runtime error.


Can it be because 'param' is invalid at the time clbck is called? The 
following program works under Linux. However, removing thread_joinAll() 
is a bug:


import std.parallelism;
import std.stdio;

alias CallBack = void function(void*);

class Foo
{
CallBack clbck;
void* param;
void dotask()
{
// some heavy processing
// tells the caller that some fresh data are available
if(clbck) clbck(param);  // debugger breaks HERE
}

void call()
{
task(&dotask).executeInNewThread;
// returns directly but the caller will get a notif when finished
}
}

void handler(void* p)
{
writefln("Finishing with %s at %s", *(cast(int*)p), p);
}

void main()
{
auto foo = new Foo();
foo.clbck = &handler;
int i = 42;
foo.param = &i;
foo.call();

import core.thread;
thread_joinAll();
}

Ali



Re: Load Qt UI XML File as GUI

2015-09-16 Thread Ali Çehreli via Digitalmars-d-learn

On 09/15/2015 09:36 PM, Steven Schveighoffer wrote:

On 9/16/15 12:03 AM, Mike McKee wrote:

Unfortunately, the http://dsource.org/forums/ doesn't appear to be
active -- I can't login after I registered. This is where the QtD
project has their forum. So, I'm asking this here.


Seems to have moved here, but it doesn't look fresh:

https://bitbucket.org/qtd/

dsource is dead (only there for archive reasons), don't use it.

-Steve


I wonder why this older one exists:

  https://github.com/qtd-developers/qtd

Ali



Re: Runtime error when calling a callback in a parallel Task

2015-09-16 Thread BBasile via Digitalmars-d-learn
On Wednesday, 16 September 2015 at 18:19:07 UTC, Ali Çehreli 
wrote:

On 09/15/2015 04:49 PM, BBasile wrote:
Under Windows this works fine but under Linux I got a runtime 
error.


Can it be because 'param' is invalid at the time clbck is 
called?


No the callback and its user parameter are set at the same time.

The following program works under Linux. However, removing 
thread_joinAll() is a bug:


I got to try `thread_joinAll`.

The main thread is not a D program so i cant call 
`thread_joinAll` that simply. Maybe as an additonal dll export 
but in this case if `thread_joinAll` does something with the 
Runtime (?) it's quite probable that it won't have an effect. :/


Re: Best Direction on Spawning Process Async

2015-09-16 Thread cka via Digitalmars-d-learn

On Wednesday, 16 September 2015 at 16:30:46 UTC, Mike McKee wrote:
This really shows the beauty and simplicity of the D language 
compared to C++. Check this out in Qt/C++:


http://stackoverflow.com/questions/32593463/spawn-async-qprocess-from-dynamic-library-peek-output-until-done

...see how much nicer the D version is here that Ali did, 
versus the Qt/C++ technique.


Here is an alternative Qt sample to handle the output of a 
process line by line and to get notified when it finishes:



#include 
#include 

int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);

QProcess scanner;

QObject::connect(&scanner, &QProcess::readyRead, [&] {
while (!scanner.atEnd()) {
auto line = scanner.readLine();
// process line
}
});

// select the QProcess::finished(int) overload
void (QProcess::*finishedSignal)(int) = &QProcess::finished;

QObject::connect(&scanner, finishedSignal, [] (int) {
   // proces finished
   QCoreApplication::quit();
});

scanner.start("avscanner");

return a.exec();
}




Re: Runtime error when calling a callback in a parallel Task

2015-09-16 Thread Ali Çehreli via Digitalmars-d-learn

On 09/16/2015 02:01 PM, BBasile wrote:
> On Wednesday, 16 September 2015 at 18:19:07 UTC, Ali Çehreli wrote:
>> On 09/15/2015 04:49 PM, BBasile wrote:
>>> Under Windows this works fine but under Linux I got a runtime error.
>>
>> Can it be because 'param' is invalid at the time clbck is called?
>
> No the callback and its user parameter are set at the same time.

I don't want to sound like insisting on my idea but I was more concerned 
about the time when param's life ended. The callback is just a function 
pointer. Functions never die, so there is no concern with that. However, 
the actual variable that 'param' is pointing at may have been gone 
before the callback is executed.


>> The following program works under Linux. However, removing
>> thread_joinAll() is a bug:
>
> I got to try `thread_joinAll`.
>
> The main thread is not a D program so i cant call `thread_joinAll` that
> simply. Maybe as an additonal dll export but in this case if
> `thread_joinAll` does something with the Runtime (?) it's quite probable
> that it won't have an effect. :/

In my code, thread_joinAll() simply made main() wait until the thread 
finished. Otherwise, if main() ended before the thread, the int data 
would be invalid when the callback was using a pointer to its (old) 
location.


Ali



Re: Runtime error when calling a callback in a parallel Task

2015-09-16 Thread BBasile via Digitalmars-d-learn
On Wednesday, 16 September 2015 at 22:30:26 UTC, Ali Çehreli 
wrote:

On 09/16/2015 02:01 PM, BBasile wrote:
> On Wednesday, 16 September 2015 at 18:19:07 UTC, Ali Çehreli
wrote:
>> On 09/15/2015 04:49 PM, BBasile wrote:
>>> Under Windows this works fine but under Linux I got a
runtime error.
>>
>> Can it be because 'param' is invalid at the time clbck is
called?
>
> No the callback and its user parameter are set at the same
time.

I don't want to sound like insisting on my idea but I was more 
concerned about the time when param's life ended. The callback 
is just a function pointer. Functions never die, so there is no 
concern with that. However, the actual variable that 'param' is 
pointing at may have been gone before the callback is executed.


>> The following program works under Linux. However, removing
>> thread_joinAll() is a bug:
>
> I got to try `thread_joinAll`.
>
> The main thread is not a D program so i cant call
`thread_joinAll` that
> simply. Maybe as an additonal dll export but in this case if
> `thread_joinAll` does something with the Runtime (?) it's
quite probable
> that it won't have an effect. :/

In my code, thread_joinAll() simply made main() wait until the 
thread finished. Otherwise, if main() ended before the thread, 
the int data would be invalid when the callback was using a 
pointer to its (old) location.


Ali


No, the param is fine. As said initially:


If i don't use a Task then the program works **fine**.


There is a synchronization problem and only under Linux.
Here is a small program that illustrates better the pattern 
(based on your previous sample):


---
import std.parallelism;

alias CallBack = void function(void*);

class Foreground
{
private Background back;
bool dataAvailable;
this()
{
back = new Background;
back.clbck = &backgroundFinished;
back.param = cast(void*) this;
}

public void something()
{
dataAvailable = false;
back.call;
}

private static void backgroundFinished(void* param)
{
with (cast(Foreground) param) dataAvailable = true;
}

// lock the access until the background thread notifies that
// interestingData is ready.
Background access()
{
if (dataAvailable)
return back;
else
return null;
}
}

class Background
{
CallBack clbck;
void* param;
private void dotask()
{
// processing on interestingData
if(clbck) clbck(param);  // debugger breaks HERE
}

void call()
{
task(&dotask).executeInNewThread;
}

public uint interestingData;
}

void main()
{
auto fore = new Foreground();
import std.random;
while (true) // you'll have to kill by hand !
{
// maybe access will be locked
if (uniform(0,100) > 95)
fore.something;
// try to see if access is readable
if (uniform(0,100) > 20)
if (fore.access) {/*can use fore.access.interesting 
data*/}

}
}
---

a class 'A' operating in the main thread is linked to a 
background class 'B' that makes some threaded updates. Other 
classes operating in the main thread can also have an access to 
the backgound class B but only through 'A' and if 'A' doesn't 
lock the access. The access is locked when 'B' is updating in a 
Thread and until 'B' notifies 'A' that the data are ready.


I use a notification because I'm afraid of the results that other 
classes could get when exploiting the 'B' interstingData. They 
only **read** them.


Anybody use Derelict FreeType recently (successfully)

2015-09-16 Thread WhatMeWorry via Digitalmars-d-learn


Compiling and linking was error free, but when I hit

DerelictFT.load();

my program aborts with the following run time message:

derelict.util.exception.SymbolLoadException@source\derelict\util\exception.d(35):
 Failed to load symbol FT_Reference_Face from shared library freetype.dll

First of all, I'm not sure if I have a valid freetype.dll file. 
How does one tell?  I downloaded freetype-2.6 but couldn't find 
anything there.  I downloaded freetype-2.3.5 and found a 
freetype6.dll which I renamed to freetype.dll because that was 
want an online discussion said.


This then caused a new error where it said that zlib1.dll could 
not be found so I downloaded that.  Ran it again and now I am 
stuck with the exception above.


Can anybody help a fellow traveler?  Thanks.




Re: Anybody use Derelict FreeType recently (successfully)

2015-09-16 Thread Mike Parker via Digitalmars-d-learn

On Thursday, 17 September 2015 at 04:58:05 UTC, WhatMeWorry wrote:


Compiling and linking was error free, but when I hit

DerelictFT.load();

my program aborts with the following run time message:

derelict.util.exception.SymbolLoadException@source\derelict\util\exception.d(35):
 Failed to load symbol FT_Reference_Face from shared library freetype.dll


This function was added to FreeType in version 2.4.2, so you will 
see this error when trying to load an older version.




First of all, I'm not sure if I have a valid freetype.dll file. 
How does one tell?  I downloaded freetype-2.6 but couldn't find 
anything there.  I downloaded freetype-2.3.5 and found a 
freetype6.dll which I renamed to freetype.dll because that was 
want an online discussion said.


DerelictFT currently requires FreeType 2.5 or later (though I've 
not yet looked into updating to the 2.6 API). What problem did 
you have with the 2.6 binary you downloaded?


Using the 2.3.5 and 2.4.2 binaries is bound to result in 
SymbolLoadExceptions, as any functions added in 2.5 will not be 
present in those binaries. You can work around this by building 
your own if you can't find anything precompiled online, but if 
you aren't using any 2.5 features, I would suggest you look into 
using DerelictUtil's selective symbol loading mechanism[1]. 
You'll need to decide a minimum version of FreeType to support, 
then diff the headers from that version with later releases to 
see which functions were added in later versions. Check for those 
functions in a MissingSymbolCallback and you can load without any 
SymbolLoadExceptions.


Also, an alternative to renaming the DLL is to pass the name 
directly to the loader:


Version(Windows) DerelictFT.load("freetype6.dll");
else DerelictFT.load();

[1] http://derelictorg.github.io/using/fail.html