| 1 |
|
| 2 |
|
| 3 |
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> |
| 4 |
<html> |
| 5 |
<head> |
| 6 |
<title>ACE FMM</title> |
| 7 |
</head> |
| 8 |
|
| 9 |
<body bgcolor=#ffffff> |
| 10 |
<center> |
| 11 |
<font face=helvetica size=5>ACE Frequently Made Mistakes</font> |
| 12 |
|
| 13 |
<br> |
| 14 |
<br> |
| 15 |
<table border=0 cellpadding=3 cellspacing=1 width=550> |
| 16 |
|
| 17 |
<tr> |
| 18 |
<td align=right valign=top> |
| 19 |
<b>symptom</b> |
| 20 |
</td> |
| 21 |
<td align=left valign=top> |
| 22 |
ACE_Task::getq() returns the error |
| 23 |
<b>resource temporarily unavailable</b> |
| 24 |
</td> |
| 25 |
</tr> |
| 26 |
<tr> |
| 27 |
<td align=right valign=top> |
| 28 |
<b>probable cause</b> |
| 29 |
</td> |
| 30 |
<td align=left valign=top> |
| 31 |
Your Task is a subclass of ACE_Task<ACE_NULL_SYNCH> and |
| 32 |
you are using it in a multithreaded program. |
| 33 |
</td> |
| 34 |
</tr> |
| 35 |
<tr> |
| 36 |
<td align=right valign=top> |
| 37 |
<b>solution</b> |
| 38 |
</td> |
| 39 |
<td align=left valign=top> |
| 40 |
Try using ACE_Task<ACE_MT_SYNCH> |
| 41 |
instead so that the associated Message_Queue |
| 42 |
is configured for access by multiple threads. |
| 43 |
</td> |
| 44 |
<tr><td colspan=2><hr noshade></td></tr> |
| 45 |
|
| 46 |
<tr> |
| 47 |
<td align=right valign=top> |
| 48 |
<b>symptom</b> |
| 49 |
</td> |
| 50 |
<td align=left valign=top> |
| 51 |
ACE_Task::wait() throws an assert violation |
| 52 |
</td> |
| 53 |
</tr> |
| 54 |
<tr> |
| 55 |
<td align=right valign=top> |
| 56 |
<b>probable cause</b> |
| 57 |
</td> |
| 58 |
<td align=left valign=top> |
| 59 |
When you activate()d your Task, you specified |
| 60 |
THR_DETACHED, which causes wait() to be unable to perform what you |
| 61 |
want it to. |
| 62 |
</td> |
| 63 |
</tr> |
| 64 |
<tr> |
| 65 |
<td align=right valign=top> |
| 66 |
<b>solution</b> |
| 67 |
</td> |
| 68 |
<td align=left valign=top> |
| 69 |
Make sure you specify the flag THR_JOINABLE when activating |
| 70 |
your ACE_Task object. |
| 71 |
</td> |
| 72 |
<tr><td colspan=2><hr noshade></td></tr> |
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
<tr> |
| 77 |
<td align=right valign=top> |
| 78 |
<b>symptom</b> |
| 79 |
</td> |
| 80 |
<td align=left valign=top> |
| 81 |
Apparent race conditions when spawning threads (or activating Tasks) |
| 82 |
from within a constructor. |
| 83 |
</td> |
| 84 |
</tr> |
| 85 |
<tr> |
| 86 |
<td align=right valign=top> |
| 87 |
<b>probable cause</b> |
| 88 |
</td> |
| 89 |
<td align=left valign=top> |
| 90 |
You are not guaranteed to have a valid <b>this</b> pointer |
| 91 |
until the constructor has exited. Threads spawned from |
| 92 |
a constructor are free to run |
| 93 |
immediately, and may attempt to use an invalid <b>this</b> pointer. |
| 94 |
|
| 95 |
</td> |
| 96 |
</tr> |
| 97 |
<tr> |
| 98 |
<td align=right valign=top> |
| 99 |
<b>solution</b> |
| 100 |
</td> |
| 101 |
<td align=left valign=top> |
| 102 |
Move your Task activations and other thread-spawning activities |
| 103 |
<b>out</b> of the constructor. |
| 104 |
</td> |
| 105 |
<tr><td colspan=2><hr noshade></td></tr> |
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
<tr> |
| 110 |
<td align=right valign=top> |
| 111 |
<b>symptom</b> |
| 112 |
</td> |
| 113 |
<td align=left valign=top> |
| 114 |
Compiler issues warnings/erros regarding using too few template |
| 115 |
arguments, such as "'ACE_Svc_Handler' : too few template arguments". |
| 116 |
</td> |
| 117 |
</tr> |
| 118 |
<tr> |
| 119 |
<td align=right valign=top> |
| 120 |
<b>probable cause</b> |
| 121 |
</td> |
| 122 |
<td align=left valign=top> |
| 123 |
Instead of using the appropriate macro, you supplied an actual class |
| 124 |
name as a parameter. This will fail depending upon platform and compiler, |
| 125 |
due to the way templates are handled. |
| 126 |
</td> |
| 127 |
</tr> |
| 128 |
<tr> |
| 129 |
<td align=right valign=top> |
| 130 |
<b>solution</b> |
| 131 |
</td> |
| 132 |
<td align=left valign=top> |
| 133 |
Instead of instantiating a template class like <b>ACE_Svc_Handler<<u>ACE_SOCK_Stream</u>, ACE_NULL_SYNCH></b>, use the form of <b>ACE_Svc_Handler<<u>ACE_SOCK_STREAM</u>, ACE_NULL_SYNCH></b> which circumvents the platform peculiarities by using the macro. This also applies to some other template classes. |
| 134 |
</td> |
| 135 |
<tr><td colspan=2><hr noshade></td></tr> |
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
<tr> |
| 140 |
<td align=right valign=top> |
| 141 |
<b>symptom</b> |
| 142 |
</td> |
| 143 |
<td align=left valign=top> |
| 144 |
Unable to compare ACE_thread_t variables (such as ACE_Thread::self()) |
| 145 |
using operator== (). |
| 146 |
</td> |
| 147 |
</tr> |
| 148 |
<tr> |
| 149 |
<td align=right valign=top> |
| 150 |
<b>probable cause</b> |
| 151 |
</td> |
| 152 |
<td align=left valign=top> |
| 153 |
On some platforms, thread ids are numeric, and on some, they aren't. On some |
| 154 |
implementations, simple a == b comparisons |
| 155 |
are legal and sane. Some are not. |
| 156 |
|
| 157 |
</td> |
| 158 |
</tr> |
| 159 |
<tr> |
| 160 |
<td align=right valign=top> |
| 161 |
<b>solution</b> |
| 162 |
</td> |
| 163 |
<td align=left valign=top> |
| 164 |
Use the <b>ACE_OS::thr_equal()</b> function to reliably compare thread |
| 165 |
ids, regardless of platform. |
| 166 |
</td> |
| 167 |
<tr><td colspan=2><hr noshade></td></tr> |
| 168 |
|
| 169 |
<tr> |
| 170 |
<td align=right valign=top> |
| 171 |
<b>symptom</b> |
| 172 |
</td> |
| 173 |
<td align=left valign=top> |
| 174 |
ACE_Reactor::run_event_loop() does not seem to function correctly |
| 175 |
for a Reactor created in your application. |
| 176 |
</td> |
| 177 |
</tr> |
| 178 |
<tr> |
| 179 |
<td align=right valign=top> |
| 180 |
<b>probable cause</b> |
| 181 |
</td> |
| 182 |
<td align=left valign=top> |
| 183 |
You have not set the ACE_Reactor::instance() to refer to your new reactor. |
| 184 |
run_event_loop only functions on the reactor currently installed as the |
| 185 |
global Singleton. |
| 186 |
</td> |
| 187 |
</tr> |
| 188 |
<tr> |
| 189 |
<td align=right valign=top> |
| 190 |
<b>solution</b> |
| 191 |
</td> |
| 192 |
<td align=left valign=top> |
| 193 |
Use the <b>ACE_Reactor::instance(ACE_Reactor *, |
| 194 |
int delete_reactor = 0)</b> static method to install your reactor as the global |
| 195 |
Singleton before calling run_event_loop(). |
| 196 |
</td> |
| 197 |
<tr><td colspan=2><hr noshade></td></tr> |
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
<tr> |
| 204 |
<td align=right valign=top> |
| 205 |
<b>symptom</b> |
| 206 |
</td> |
| 207 |
<td align=left valign=top> |
| 208 |
Infinite recursion when you invoke ACE_Reactor::remove_handler() |
| 209 |
</td> |
| 210 |
</tr> |
| 211 |
<tr> |
| 212 |
<td align=right valign=top> |
| 213 |
<b>probable cause</b> |
| 214 |
</td> |
| 215 |
<td align=left valign=top> |
| 216 |
You are invoking remove_handler() from within handle_close() (or a |
| 217 |
method invoked by handle_close()) but you have not specified the |
| 218 |
DONT_CALL flag. |
| 219 |
</td> |
| 220 |
</tr> |
| 221 |
<tr> |
| 222 |
<td align=right valign=top> |
| 223 |
<b>solution</b> |
| 224 |
</td> |
| 225 |
<td align=left valign=top> |
| 226 |
Be sure to <b>OR</b> in the DONT_CALL flag in this situation.<br> |
| 227 |
e.g. --<br> |
| 228 |
<ul><pre> |
| 229 |
int MyHandler::handle_close (ACE_HANDLE handle, |
| 230 |
ACE_Reactor_Mask close_mask) |
| 231 |
{ |
| 232 |
... |
| 233 |
my_reactor_->remove_handler( this, |
| 234 |
ACE_Event_Handler::READ_MASK | |
| 235 |
ACE_Event_Handler::DONT_CALL ); |
| 236 |
... |
| 237 |
return 0; |
| 238 |
} |
| 239 |
</pre></ul> |
| 240 |
|
| 241 |
</td> |
| 242 |
<tr><td colspan=2><hr noshade></td></tr> |
| 243 |
|
| 244 |
<tr> |
| 245 |
<td align=right valign=top> |
| 246 |
<b>symptom</b> |
| 247 |
</td> |
| 248 |
<td align=left valign=top> |
| 249 |
Application crashes after deleting Event_Handler. |
| 250 |
</td> |
| 251 |
</tr> |
| 252 |
<tr> |
| 253 |
<td align=right valign=top> |
| 254 |
<b>probable cause</b> |
| 255 |
</td> |
| 256 |
<td align=left valign=top> |
| 257 |
You left a dangling pointer to the Event_Handler in the Reactor. |
| 258 |
It is the application's responsibility to remove all pending notifications, |
| 259 |
timer events and completely remove the event handler I/O registrations |
| 260 |
before removing the event handler. |
| 261 |
|
| 262 |
Also, the application should remove the event handler from the reactor |
| 263 |
<b>before</b> closing the underlying file descriptor / handle. |
| 264 |
Otherwise: |
| 265 |
<ul> |
| 266 |
<li>The reactor does not know how to remove the event handler, because the |
| 267 |
handle is used as the identifier for the event handlers</li> |
| 268 |
<li>The file descriptor / handle may be reused by another thread, leading to |
| 269 |
nasty race conditions.</li> |
| 270 |
</ul> |
| 271 |
</td> |
| 272 |
</tr> |
| 273 |
<tr> |
| 274 |
<td align=right valign=top> |
| 275 |
<b>solution</b> |
| 276 |
</td> |
| 277 |
<td align=left valign=top> |
| 278 |
<ul> |
| 279 |
<li>Use reference counted event handlers. The reactor and the application |
| 280 |
cooperate to remove the event handler when the last reference goes away. |
| 281 |
</li> |
| 282 |
<li>Remember to call <tt>purge_pending_notifications()</tt>, |
| 283 |
<tt>remove_handler()</tt> and <tt>cancel_timer()</tt> before deleting the |
| 284 |
event handler. |
| 285 |
</li> |
| 286 |
</ul> |
| 287 |
</td> |
| 288 |
<td align=left valign=top> |
| 289 |
|
| 290 |
</td> |
| 291 |
<tr><td colspan=2><hr noshade></td></tr> |
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
<tr> |
| 322 |
<td align=center colspan=2> |
| 323 |
<font size=2>maintained by <a href="mailto:[email protected]">[email protected]</a></font> |
| 324 |
</td> |
| 325 |
</tr> |
| 326 |
|
| 327 |
</table> |
| 328 |
</center> |
| 329 |
Back to <A HREF="index.html">ACE Documentation Home</A>. |
| 330 |
</body> |
| 331 |
</html> |
| 332 |
|