D create many thread

2020-02-05 Thread Eko Wahyudin via Digitalmars-d-learn

Hi all,

I'm create a small (hallo world) application, with DMD.
But my program create 7 annoying threads when create an empty 
class.


What is this thread for?
and is it normal in D?

Below the stack trace of thread creation.

#0  0x77f637a0 in pthread_create@@GLIBC_2.2.5 () from 
/usr/lib/libpthread.so.0
#1  0x557388d0 in 
core.thread.osthread.createLowLevelThread(void() nothrow 
delegate, uint, void() nothrow delegate) ()
#2  0x55731384 in 
_D2gc4impl12conservativeQw3Gcx16startScanThreadsMFNbZv ()
#3  0x557307ba in 
_D2gc4impl12conservativeQw3Gcx11fullcollectMFNbbZm ()
#4  0x5572eccc in 
_D2gc4impl12conservativeQw3Gcx10smallAllocMFNbmKmkxC8TypeInfoZPv 
()
#5  0x557346a9 in 
_D2gc4impl12conservativeQw14ConservativeGC__T9runLockedS_DQCeQCeQCcQCnQBs12mallocNoSyncMFNbmkKmxC8TypeInfoZPvS_DQEgQEgQEeQEp10mallocTimelS_DQFiQFiQFgQFr10numMallocslTmTkTmTxQCzZQFcMFNbKmKkKmKxQDsZQDl ()
#6  0x5572c2fe in 
_D2gc4impl12conservativeQw14ConservativeGC6mallocMFNbmkxC8TypeInfoZPv ()

#7  0x556cd163 in gc_malloc ()
#8  0x556f529c in 
_D2gc4impl5protoQo7ProtoGC6mallocMFNbmkxC8TypeInfoZPv ()

#9  0x556cd163 in gc_malloc ()
#10 0x556cf55b in _d_newclass ()
#11 0x556669f4 in D main (args=...) at source/app.d:11
(gdb) info threads
  Id   Target IdFrame
* 1Thread 0x77c1ea40 (LWP 8288) "jala2" 
0x77f637a0 in pthread_create@@GLIBC_2.2.5 () from 
/usr/lib/libpthread.so.0
  2Thread 0x77fcc700 (LWP 8289) "jala2" 
0x77f69c45 in pthread_cond_wait@@GLIBC_2.3.2 () from 
/usr/lib/libpthread.so.0
  3Thread 0x77fc7700 (LWP 8317) "jala2" 
0x77f69c45 in pthread_cond_wait@@GLIBC_2.3.2 () from 
/usr/lib/libpthread.so.0
  4Thread 0x77fc2700 (LWP 8329) "jala2" 
0x77f69c45 in pthread_cond_wait@@GLIBC_2.3.2 () from 
/usr/lib/libpthread.so.0
  5Thread 0x77fbd700 (LWP 8439) "jala2" 
0x77f69c45 in pthread_cond_wait@@GLIBC_2.3.2 () from 
/usr/lib/libpthread.so.0
  6Thread 0x77fb8700 (LWP 8445) "jala2" 
0x77f69c45 in pthread_cond_wait@@GLIBC_2.3.2 () from 
/usr/lib/libpthread.so.0
  7Thread 0x77fb3700 (LWP 8463) "jala2" 
0x77f69c45 in pthread_cond_wait@@GLIBC_2.3.2 () from 
/usr/lib/libpthread.so.0



Thank you in advance.


Re: How to iterate getSymbolsByUDA

2018-11-27 Thread Eko Wahyudin via Digitalmars-d-learn

static foreach(sym; getSymbolsByUDA!(A, Attr)){
   writeln(sym.stringof); // print variable name "a" this what i 
want

}

foreach(sym; getSymbolsByUDA!(A, Attr)){
   writeln(sym.stringof);  // print "sym"
}

foreach(sym; getSymbolsByUDA!(A, Attr)){
   writeln(__traits(identifier, sym)); //also print "sym"
}

is there a way to get variable name using foreach like static 
foreach?


Re: How to iterate getSymbolsByUDA

2018-11-26 Thread Eko Wahyudin via Digitalmars-d-learn

On Sunday, 25 November 2018 at 01:01:30 UTC, bauss wrote:
On Saturday, 24 November 2018 at 08:50:59 UTC, Eko Wahyudin 
wrote:
On Saturday, 24 November 2018 at 08:09:38 UTC, Stanislav 
Blinov wrote:

[...]


aah ya,, this statement is work

static foreach (i; 0 .. symbols.length)

thank you.


It should work with just:

static foreach(sym; getSymbolsByUDA!(A, Attr)){
  ...
}

or

alias symbols = getSymbolsByUDA!(A, Attr);

static foreach(sym; symbols){
  ...
}


---

What you were missing was just making it a static foreach.


seems my problem is i use GDC, i got this error

error: basic type expected, not foreach.



Re: How to iterate getSymbolsByUDA

2018-11-24 Thread Eko Wahyudin via Digitalmars-d-learn
On Saturday, 24 November 2018 at 08:09:38 UTC, Stanislav Blinov 
wrote:
On Saturday, 24 November 2018 at 03:48:12 UTC, Eko Wahyudin 
wrote:

Hi all,
anyone know how to iterate getSymbolsByUDA ?


enum Attr;
struct A
{
@Attr int a;
int b;

@Attr void foo() {}
@Attr void foo(int) {}
}

void main() {
import std.traits;
import std.stdio;

alias symbols = getSymbolsByUDA!(A, Attr);

A a;

static foreach (i; 0 .. symbols.length) {
writeln("identifier: ", __traits(identifier, 
symbols[i]));

static if (is(typeof(symbols[i]) == int)) {
__traits(getMember, a, __traits(identifier, 
symbols[i])) = 42;

}
}

assert(a.a == 42);
}


aah ya,, this statement is work

static foreach (i; 0 .. symbols.length)

thank you.


How to iterate getSymbolsByUDA

2018-11-23 Thread Eko Wahyudin via Digitalmars-d-learn

Hi all,
anyone know how to iterate getSymbolsByUDA ?

I try this code:

enum Attr;
struct A
{
@Attr int a;
int b;
}

//---
//1. Error: need `this` for `a` of type `int`
foreach(sym; getSymbolsByUDA!(A, Attr)){
writeln(sym.stringof);  
}


for(sizediff_t i=0; i

how to make interface with return auto

2017-04-03 Thread Eko Wahyudin via Digitalmars-d-learn

I know it's imposible.

is there's a way if i want to create an interface that have 
method with return type value is equals with return type of 
std.palallelism.task


eg.
interface IWorker{
   auto activate(); //on implementation class activate return 
std.parallelism.task

}

What is the replacement of auto on that interface?

Thank you!


How delegate context work?

2017-03-16 Thread Eko Wahyudin via Digitalmars-d-learn

I'm writing promise library, and perform testing like this..


app = new Application();
Promise p = app.exec(delegate void(){ // first delegate
write("Hello");
std.stdio.stdout.flush;
int xxx = 777;
auto p2 = app.exec!int(delegate int(){ // second 
delegate
return xxx;
});

p2.success = delegate void(int result){
writefln("We got result:%d",result);
};
});
with(p){
success = delegate void(){
writeln(" world");
};
}

app.run();

When the my library executing second promise, Supprisingly I got 
amazing result, I can do same thing that javascript can do.


I printed "We got result:777".

My question is, on seconds delegate.

How D access xxx variable? where context pointer refer to?
How D keep xxx variable persistent?
Why xxx is not swapped out when we leave first delegate?

isn't that if we leave first delegate we execute RET n (on intel 
processor) and make the stack available for another call? so xxx 
memory address used by another function?


how this magic thing happen? or i just lucky got uncertain value 
but the value is 777 ?



Thank you guys, before.