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 periodically in order to |
4 |
//order to unstall certain Windows programs and scripts. The cause of the stall is unknown, but |
//unstall certain Windows programs and scripts. The cause of the stall is unknown, but |
5 |
//it is known that spawning threads and/or processes unstalls the system. |
//it is known that spawning threads unstalls the system. |
6 |
//------------------------------------------------------------------------------------------------- |
//------------------------------------------------------------------------------------------------- |
7 |
//This source code and any program in which it is compiled/used is provided under the MIT License, |
//This source code and any program in which it is compiled/used is provided under the MIT License, |
8 |
//reproduced below. |
//reproduced below. |
25 |
//OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
//OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
26 |
//SOFTWARE. |
//SOFTWARE. |
27 |
//------------------------------------------------------------------------------------------------- |
//------------------------------------------------------------------------------------------------- |
|
#include <assert.h> |
|
|
#include <malloc.h> |
|
28 |
#include <process.h> |
#include <process.h> |
29 |
#include <stdio.h> |
#include <stdio.h> |
30 |
#include <string.h> |
#include <string.h> |
|
#include <time.h> |
|
31 |
#include <windows.h> |
#include <windows.h> |
32 |
|
|
33 |
#define NELEM(A) (sizeof(A)/sizeof(A[0])) |
#define NELEM(A) (sizeof(A)/sizeof(A[0])) |
34 |
|
|
35 |
void emit_hline_std(void) |
void emit_hline_std(void) |
36 |
{ |
{ |
37 |
printf("----------------------------------------------------------------------------------\n"); |
printf("-------------------------------------------------------------------------------\n"); |
38 |
} |
} |
39 |
|
|
40 |
void emit_mit_license(void) |
void emit_mit_license(void) |
41 |
{ |
{ |
42 |
const char *ref[] = |
const char *ref[] = |
43 |
{ |
{ |
44 |
"Permission is hereby granted, free of charge, to any person obtaining a copy of", |
"Permission is hereby granted, free of charge, to any person obtaining a copy", |
45 |
"this software and associated documentation files(the \"Software\"), to deal in the", |
"of this software and associated documentation files(the \"Software\"), to", |
46 |
"Software without restriction, including without limitation the rights to use,", |
"deal in the Software without restriction, including without limitation the", |
47 |
"copy, modify, merge, publish, distribute, sublicense, and / or sell copies of the", |
"rights to use, copy, modify, merge, publish, distribute, sublicense, and / or", |
48 |
"Software, and to permit persons to whom the Software is furnished to do so,", |
"sell copies of the Software, and to permit persons to whom the Software is", |
49 |
"subject to the following conditions :", |
"furnished to do so, subject to the following conditions :", |
50 |
"", |
"", |
51 |
"The above copyright notice and this permission notice shall be included in all", |
"The above copyright notice and this permission notice shall be included in", |
52 |
"copies or substantial portions of the Software.", |
"all copies or substantial portions of the Software.", |
53 |
"", |
"", |
54 |
"THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR", |
"THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR", |
55 |
"IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,", |
"IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,", |
114 |
|
|
115 |
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 |
116 |
//CTRL-C or CTRL-BREAK. |
//CTRL-C or CTRL-BREAK. |
117 |
|
volatile int thread_ran = 0; //volatile because shared with thread. |
118 |
|
|
119 |
BOOL CtrlHandler(DWORD fdwCtrlType) |
BOOL CtrlHandler(DWORD fdwCtrlType) |
120 |
{ |
{ |
133 |
//blow up and wipe out several city blocks! |
//blow up and wipe out several city blocks! |
134 |
} |
} |
135 |
|
|
136 |
|
//Thread function. Parameter ignored. |
137 |
|
DWORD WINAPI MyThreadFunction(LPVOID lpParam) |
138 |
|
{ |
139 |
|
thread_ran = 1; |
140 |
|
|
141 |
|
return (0); |
142 |
|
} |
143 |
|
|
144 |
int c_main(int argc, char* argv[]) |
int c_main(int argc, char* argv[]) |
145 |
{ |
{ |
146 |
size_t selector = NELEM(kickish_words) - 1; |
size_t selector = NELEM(kickish_words) - 1; |
147 |
size_t ui; |
size_t ui; |
148 |
int first_time = 1; |
int first_time = 1; |
149 |
|
HANDLE thread_handle; |
150 |
|
DWORD thread_id; |
151 |
|
|
152 |
emit_hline_std(); |
emit_hline_std(); |
153 |
printf("kicker, Copyright 2016 David T. Ashley (dashley@gmail.com)\n"); |
printf("kicker, Copyright 2016 David T. Ashley (dashley@gmail.com)\n"); |
154 |
emit_hline_std(); |
emit_hline_std(); |
155 |
printf("This program is provided under the MIT License, reproduced below.\n"); |
printf("This program is made available under the MIT License, reproduced below.\n"); |
156 |
emit_hline_std(); |
emit_hline_std(); |
157 |
emit_mit_license(); |
emit_mit_license(); |
158 |
emit_hline_std(); |
emit_hline_std(); |
198 |
//Print the description. |
//Print the description. |
199 |
printf("%s!", kickish_words[selector]); |
printf("%s!", kickish_words[selector]); |
200 |
|
|
201 |
//Delay. Sleep() is likely the most effective way to not waste CPU capacity. |
//Start the thread. This will hopefully unstall things. |
202 |
|
thread_handle = CreateThread( |
203 |
|
NULL, // default security attributes |
204 |
|
0, // use default stack size |
205 |
|
MyThreadFunction, // thread function name |
206 |
|
0, // argument to thread function |
207 |
|
0, // use default creation flags |
208 |
|
&thread_id); // returns the thread identifier |
209 |
|
|
210 |
|
//If the create call failed, terminate. |
211 |
|
if (thread_handle == NULL) |
212 |
|
{ |
213 |
|
printf("\nOuch!\n"); |
214 |
|
exit(0); |
215 |
|
} |
216 |
|
|
217 |
|
//Wait for thread termination. This should be nearly instant. But it |
218 |
|
//would seem to be the best way to wait so as not to chew up CPU |
219 |
|
//cycles. |
220 |
|
WaitForSingleObject(thread_handle, INFINITE); |
221 |
|
|
222 |
|
//At this point, the thread should have run, and the variable should have been |
223 |
|
//set. If not, there is a real logical problem. |
224 |
|
if (!thread_ran) |
225 |
|
{ |
226 |
|
printf("\nDouble-ouch\n"); |
227 |
|
exit(0); |
228 |
|
} |
229 |
|
|
230 |
|
thread_ran = 0; |
231 |
|
|
232 |
|
//Delay. Sleep() is likely the most effective way to not waste CPU capacity. |
233 |
Sleep(1000); |
Sleep(1000); |
234 |
} |
} |
235 |
|
|