/[dtapublic]/projs/trunk/projs/20161106_kicker/c_main.c
ViewVC logotype

Diff of /projs/trunk/projs/20161106_kicker/c_main.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 78 by dashley, Mon Nov 7 03:39:51 2016 UTC revision 79 by dashley, Mon Nov 7 17:06:44 2016 UTC
# Line 1  Line 1 
1  // $Header$  //$Header$
2  //-------------------------------------------------------------------------------------------------  //-------------------------------------------------------------------------------------------------
3  //This file is part of "kicker", a program for spawning threads and/or processes periodically in  //This file is part of "kicker", a program for spawning threads and/or processes periodically in
4  //order to unstall certain Windows programs and scripts.  The cause of the stall is unknown, but  //order to unstall certain Windows programs and scripts.  The cause of the stall is unknown, but
# Line 117  const char *kickish_words[] = Line 117  const char *kickish_words[] =
117    
118  volatile int ctrl_c_or_break_pressed = 0;  //volatile because the Visual C++ environment spawns a thread to handle  volatile int ctrl_c_or_break_pressed = 0;  //volatile because the Visual C++ environment spawns a thread to handle
119                                             //CTRL-C or CTRL-BREAK.                                             //CTRL-C or CTRL-BREAK.
120    volatile int thread_ran = 0;               //volatile because shared with thread.
121    
122    
123  BOOL CtrlHandler(DWORD fdwCtrlType)  BOOL CtrlHandler(DWORD fdwCtrlType)
124  {  {
# Line 135  BOOL CtrlHandler(DWORD fdwCtrlType) Line 137  BOOL CtrlHandler(DWORD fdwCtrlType)
137                     //blow up and wipe out several city blocks!                     //blow up and wipe out several city blocks!
138  }  }
139    
140    
141    //Thread function.  Parameter ignored.
142    DWORD WINAPI MyThreadFunction(LPVOID lpParam)
143    {
144       thread_ran = 1;
145    
146       return (0);
147    }
148    
149    
150  int c_main(int argc, char* argv[])  int c_main(int argc, char* argv[])
151  {  {
152     size_t selector = NELEM(kickish_words) - 1;     size_t selector = NELEM(kickish_words) - 1;
153     size_t ui;     size_t ui;
154     int first_time = 1;     int first_time = 1;
155       HANDLE thread_handle;
156       DWORD  thread_id;
157    
158     emit_hline_std();     emit_hline_std();
159     printf("kicker, Copyright 2016 David T. Ashley (dashley@gmail.com)\n");     printf("kicker, Copyright 2016 David T. Ashley (dashley@gmail.com)\n");
# Line 190  int c_main(int argc, char* argv[]) Line 204  int c_main(int argc, char* argv[])
204         //Print the description.         //Print the description.
205         printf("%s!", kickish_words[selector]);         printf("%s!", kickish_words[selector]);
206    
207         //Delay.  Sleep() is likely the most effective way to not waste CPU capacity.             //Start the thread.  This will hopefully unstall things.
208               thread_handle = CreateThread(
209                       NULL,                   // default security attributes
210                       0,                      // use default stack size  
211                       MyThreadFunction,       // thread function name
212                       0,                      // argument to thread function
213                       0,                      // use default creation flags
214                       &thread_id);            // returns the thread identifier
215    
216               //If the create call failed, terminate.
217               if (thread_handle == NULL)
218               {
219                       printf("\nOuch!\n");
220                       exit(0);
221               }
222    
223               //Wait for thread termination.  This should be nearly instant.  But it
224               //would seem to be the best way to wait so as not to chew up CPU
225               //cycles.
226               WaitForSingleObject(thread_handle, INFINITE);
227    
228               //At this point, the thread should have run, and the variable should have been
229               //set.  If not, there is a real logical problem.
230               if (!thread_ran)
231               {
232                       printf("\nDouble-ouch\n");
233                       exit(0);
234               }
235    
236               thread_ran = 0;
237    
238               //Delay.  Sleep() is likely the most effective way to not waste CPU capacity.
239         Sleep(1000);         Sleep(1000);
240     }     }
241    

Legend:
Removed from v.78  
changed lines
  Added in v.79

dashley@gmail.com
ViewVC Help
Powered by ViewVC 1.1.25