OSDN Git Service

* thread.cc (pthread::create): Use thread mutex to control synchronization
authorcgf <cgf>
Tue, 13 Apr 2004 02:59:19 +0000 (02:59 +0000)
committercgf <cgf>
Tue, 13 Apr 2004 02:59:19 +0000 (02:59 +0000)
rather than creating a suspended thread.  Wait for "cancellation event" to
indicate that started thread has been properly initialized.
(pthread::thread_init_wrapper): Use set_tls_self_pointer() to set tid and
cygtls.  Signal with cancel_event when done.

winsup/cygwin/ChangeLog
winsup/cygwin/thread.cc

index 3587b03..ce65d3e 100644 (file)
@@ -1,6 +1,15 @@
+2004-04-12  Christopher Faylor  <cgf@alum.bu.edu>
+
+       * thread.cc (pthread::create): Use thread mutex to control
+       synchronization rather than creating a suspended thread.  Wait for
+       "cancellation event" to indicate that started thread has been properly
+       initialized.
+       (pthread::thread_init_wrapper): Use set_tls_self_pointer() to set tid
+       and cygtls.  Signal with cancel_event when done.
+
 2004-04-12  Pierre Humblet <pierre.humblet@ieee.org>
 
-        * path.cc (path_conv::check): Fix "tail filling" logic.
+       * path.cc (path_conv::check): Fix "tail filling" logic.
 
 2004-04-11  Christopher Faylor  <cgf@alum.bu.edu>
 
        (FHSTATOFF): Remove.
        (UNCONNECTED, CONNECT_PENDING, CONNECTED): Substitute by enum
        connect_state.
-       (fhandler_base::status): Define as bitfield struct type status_flags. 
+       (fhandler_base::status): Define as bitfield struct type status_flags.
        Remove unused flags entirely.  Accomodate all status access methods.
        (open_status): Define as bitfield struct type status_flags.
        (fhandler_socket): Move socket related status bits to here.  Redefine
        had_connect_or_listen to be part of these status bits.  Accomodate
        related access methods.
        * fhandler_disk_file.cc (fhandler_base::fstat_helper): Use pc.issymlink
-       instead of dropped method get_symlink_p. 
+       instead of dropped method get_symlink_p.
        (fhandler_base::open_fs): Remove setting dropped status flags.
        * fhandler_socket.cc: Use values from enum connect_state throughout.
        (fhandler_socket::fhandler_socket): Initialize status bits.
        * shm.cc (shmat): If shmid is unknown, call a special variation
        of shmget to retrieve the shared memory segment from Cygserver
        instead of failing immediately.
-       * include/cygwin/ipc.h (IPC_KEY_IS_SHMID): New internal flag for 
+       * include/cygwin/ipc.h (IPC_KEY_IS_SHMID): New internal flag for
        shmget when called from shmat.
 
 2004-03-29  Corinna Vinschen  <corinna@vinschen.de>
        * autoload.cc: Load eight more functions for waveIn support.
        * fhandler.h (class fhandler_dev_dsp): Add class Audio, class Audio_in
        and class Audio_out members and audio_in_, audio_out_ pointers so
-       that future changes are restricted to file fhandler_dsp.cc.  
+       that future changes are restricted to file fhandler_dsp.cc.
        * fhandler_dsp.cc (fhandler_dev_dsp::Audio): Add this class to treat
        things common to audio recording and playback.
        Add more format conversions.
 
 2004-03-19  Pierre Humblet <pierre.humblet@ieee.org>
 
-        * dir.cc (rmdir): Reorganize error handling to reduce indentation.
+       * dir.cc (rmdir): Reorganize error handling to reduce indentation.
+
 2004-03-19  Christopher Faylor  <cgf@redhat.com>
 
        * include/cygwin/version.h: Bump DLL minor number to 10.
        (fhandler_dev_tape::read_file): Ditto.
        (fhandler_dev_tape::tape_get_feature): Convert to inline method.
        (fhandler_dev_tape::tape_error): New method, created from former
-       static function. 
+       static function.
        (fhandler_dev_tape::tape_get_blocksize): Remove declaration.
        * fhandler_raw.cc (fhandler_dev_raw::write_file): New method, created
        from former static function.
index 5607442..24c3f56 100644 (file)
@@ -290,9 +290,9 @@ pthread::create (void *(*func) (void *), pthread_attr *newattr,
   function = func;
   arg = threadarg;
 
+  mutex.lock ();
   win32_obj_id = ::CreateThread (&sec_none_nih, attr.stacksize,
-                               thread_init_wrapper, this, CREATE_SUSPENDED,
-                               &thread_id);
+                               thread_init_wrapper, this, 0, &thread_id);
 
   if (!win32_obj_id)
     {
@@ -301,9 +301,12 @@ pthread::create (void *(*func) (void *), pthread_attr *newattr,
     }
   else
     {
+      if (WaitForSingleObject (cancel_event, 5000) != WAIT_OBJECT_0)
+       thread_printf ("event never arrived after CreateThread");
+      ResetEvent (cancel_event);
       postcreate ();
-      ResumeThread (win32_obj_id);
     }
+  mutex.unlock ();
 }
 
 void
@@ -1861,7 +1864,8 @@ DWORD WINAPI
 pthread::thread_init_wrapper (void *arg)
 {
   pthread *thread = (pthread *) arg;
-  _my_tls.tid = thread;
+  set_tls_self_pointer (thread);
+  SetEvent (thread->cancel_event);
 
   thread->mutex.lock ();