• Post Reply Bookmark Topic Watch Topic
  • New Topic

Control over the main thread

 
Julien Martin
Ranch Hand
Posts: 384
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I am just wondering how to refer to the main thread if that's possible at all. Say I want to invoke the method join() on the main thread. How is that possible? (the point here would be for a another thread to wait for the main thread to die before proceeding.)
Any clue?
Julien.
 
Henry Wong
author
Sheriff
Posts: 22542
109
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The easiest way to do it, is probably cooperatively. Have the main thread pass it's Thread object when it creates the other thread, or have the main thread save it's thread object somewhere, at the beginning of the main method.

If you didn't change the thread group, you can also enumerate through all the threads, looking for the thread with the name "main".

Henry
 
Julien Martin
Ranch Hand
Posts: 384
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Henry and thanks for your reply,
1. I am honoured an author of O'Reilly replies to my posts
2. Can you please give me some code samples for what you describe...
Thanks,
Julien.
 
Henry Wong
author
Sheriff
Posts: 22542
109
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, there are countless way to have the main thread cooperatively store the thread object. One way is like so...



Once it is stored, you can do this...



Henry
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!