../pvss.htm menu.gif basics.gif

waitThread()

Waits for the end of the specified thread.

Synopsis

Parameters

Return value

0, in the event of errors -1.

Errors

Missing/incorrect argument, for example, the specified thread does not exist.

Description

Waits for the thread with the identification number threadId.

note.gifNote

It is only possible to wait for scripts, which have been started in the own script and it is not possible to wait for one's own thread: waitThread(getThreadId()).

IconExample

void myFunction()
{
  DebugTN("begin of thread");
  int a;
  for (a = 0; a < 10; a++)
  {
       DebugTN(getThreadId(), a);
       delay(1);
  }
  DebugTN("end of thread");
}


/*

A) with waitThread() -> main() is waiting after startThread() as long as the thread does not finish

*/

main()
{
  DebugTN("begin of main");
  int id = startThread("myFunction");
  waitThread(id);
  DebugTN("end of main");
}

/* Output in Log Viewer:

WCCOAui1:2010.11.24 16:28:18.128["begin of main"]
WCCOAui1:2010.11.24 16:28:18.191["begin of thread"]
WCCOAui1:2010.11.24 16:28:18.191[1][0]
WCCOAui1:2010.11.24 16:28:19.191[1][1]
WCCOAui1:2010.11.24 16:28:20.191[1][2]
WCCOAui1:2010.11.24 16:28:21.191[1][3]
WCCOAui1:2010.11.24 16:28:22.191[1][4]
WCCOAui1:2010.11.24 16:28:23.191[1][5]
WCCOAui1:2010.11.24 16:28:24.191[1][6]
WCCOAui1:2010.11.24 16:28:25.191[1][7]
WCCOAui1:2010.11.24 16:28:26.191[1][8]
WCCOAui1:2010.11.24 16:28:27.191[1][9]
WCCOAui1:2010.11.24 16:28:28.191["end of thread"]
WCCOAui1:2010.11.24 16:28:28.191["end of main"]

*/

/*

B) without waitThread() -> main() will finish immediately after startThread() call

*/

main()
{
  DebugTN("begin of main");
  int id = startThread("myFunction");
//  waitThread(id);

  DebugTN("end of main");
}

/* Output in Log Viewer:

WCCOAui1:2010.11.24 16:29:54.881["begin of main"]
WCCOAui1:2010.11.24 16:29:54.959["begin of thread"]
WCCOAui1:2010.11.24 16:29:54.959["end of main"]
WCCOAui1:2010.11.24 16:29:54.959[1][0]
WCCOAui1:2010.11.24 16:29:55.959[1][1]
WCCOAui1:2010.11.24 16:29:56.959[1][2]
WCCOAui1:2010.11.24 16:29:57.959[1][3]
WCCOAui1:2010.11.24 16:29:58.959[1][4]
WCCOAui1:2010.11.24 16:29:59.959[1][5]
WCCOAui1:2010.11.24 16:30:00.959[1][6]
WCCOAui1:2010.11.24 16:30:01.959[1][7]
WCCOAui1:2010.11.24 16:30:02.959[1][8]
WCCOAui1:2010.11.24 16:30:03.959[1][9]
WCCOAui1:2010.11.24 16:30:04.959["end of thread"]

*/

Relates to

Threads

Availability

UI, CTRL, DP

See also

Top Of Page

 

V 3.11 SP1

Copyright ETM professional control GmbH 2013 All Rights Reserved