Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: gcc / cygwin threads revisited

Author: James Swafford

Date: 17:27:09 07/24/99

Go up one level in this thread


On July 24, 1999 at 17:19:31, James Swafford wrote:

I've done some experimenting today, and discovered that
gcc (or at least the cygwin port) will not let a multithreaded
program terminate until each thread in the program has
called exit( ), or returned from main.

One frustrating question still remains.  Please examine
the code segment below:

**********
   ui_thread_is_dead=0;

   // start ui thread
//   beginthread(UIThread,0,0);
   if (!fork()) {
      UIThread(NULL);
      ui_thread_is_dead=1;
      cout << "terminating child thread...\n" << flush;
      return 0;
   }

   cout << "executing parent thread\n";
   while (!ui_thread_is_dead) {
   }

   cout << "terminating parent thread...\n" << flush;
   return 0;
**********

Once the program starts, the friendly message
"executing parent thread" is displayed.

Once I type "quit," which is handled by UIThread( ),
the message "terminating child thread..." is displayed.
At this point the variable ui_thread_is_dead *should* be=1,
but for some reason it's not.

The message "terminating parent thread" is never displayed,
and the program never terminates.  Ugh.

Any insight would be greatly appreciated. :-/

--
James





>
>I posted a question several days ago about the gcc
>equivalent to MSVC's "beginthread( )" .
>
>Bob replied with "fork( )", which does the job, but
>there's one rather ugly side effect:  the program
>won't terminate.
>
>To be more specific, when I type "quit", the user
>thread parses the input and processes it, but for
>some reason when the call to exit( ) is performed,
>the whole process freezes.  The same thing happens
>when executing "return" from main( ).
>
>This doesn't happen when the program is running test
>suites, simply because the UIThread( ) is never started.
>When the suite is complete, the program exits cleanly.
>
>Perhaps threads are handled differently than with MSVC.
>Is it okay to call exit( ) from within UIThread( )?
>Would it be better to have UIThread( ) return some variable
>indicating the program should terminate, then somehow kill
>the thread, then call exit( ) from the "main thread"?  If so,
>how do I kill a thread with gcc / cygwin?
>
>--
>James



This page took 0 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.