thread funtion is broken?

Discussions about product bugs & problems!
Note: This is no replacement for the Official ETM Support!
3 posts • Page 1 of 1
kilianvp
Posts:443
Joined: Fri Jan 16, 2015 10:29 am

thread funtion is broken?

Post by kilianvp »

i took the example for threads form the help. The Problem is that booth threads have the same ID

Code: Select all

void myFunction()
{
int a;
for (a = 0; a < 10; a++)
DebugN(getThreadId(), a);
}
main()
{
startThread("myFunction");
/*startet einen neuen Thread der Funktion "myFunction"*/
startThread("myFunction"); 
/*startet parallel einen 2.Thread wobei jeder Thread für sich von 0 bis
9 zählt und die jeweilige Threadnummer ausgibt*/
}
but the output is:

Code: Select all

WCCOAui1:[1][0]
WCCOAui1:[1][1]
WCCOAui1:[1][2]
WCCOAui1:[1][3]
WCCOAui1:[1][4]
WCCOAui1:[1][5]
WCCOAui1:[1][6]
WCCOAui1:[1][7]
WCCOAui1:[1][8]
WCCOAui1:[1][9]
WCCOAui1:[1][0]
WCCOAui1:[1][1]
WCCOAui1:[1][2]
WCCOAui1:[1][3]
WCCOAui1:[1][4]
WCCOAui1:[1][5]
WCCOAui1:[1][6]
WCCOAui1:[1][7]
WCCOAui1:[1][8]
WCCOAui1:[1][9]

however if i add another Thread the output is:

Code: Select all

WCCOAui1:[1][0]
WCCOAui1:[1][1]
WCCOAui1:[1][2]
WCCOAui1:[1][3]
WCCOAui1:[1][4]
WCCOAui1:[1][5]
WCCOAui1:[1][6]
WCCOAui1:[1][7]
WCCOAui1:[1][8]
WCCOAui1:[1][9]
WCCOAui1:[2][0]
WCCOAui1:[2][1]
WCCOAui1:[2][2]
WCCOAui1:[2][3]
WCCOAui1:[2][4]
WCCOAui1:[2][5]
WCCOAui1:[2][6]
WCCOAui1:[2][7]
WCCOAui1:[2][8]
WCCOAui1:[2][9]
WCCOAui1:[1][0]
WCCOAui1:[1][1]
WCCOAui1:[1][2]
WCCOAui1:[1][3]
WCCOAui1:[1][4]
WCCOAui1:[1][5]
WCCOAui1:[1][6]
WCCOAui1:[1][7]
WCCOAui1:[1][8]
WCCOAui1:[1][9]

mkoller
Posts:741
Joined: Fri Sep 17, 2010 9:03 am

Re: thread funtion is broken?

Post by mkoller »

The first thread is finishing its work before the new thread starts. That means, the first thread gets id 1, finishes, therefore frees number 1, then the
next thread starts having again number 1.
When you change the code in myFunction a bit, then you'll see both threads running in parallel.
e.g. { delay(0,1); DebugN(getThreadId(), a); }

kilianvp
Posts:443
Joined: Fri Jan 16, 2015 10:29 am

Re: thread funtion is broken?

Post by kilianvp »

thank you :)

3 posts • Page 1 of 1