<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body>
<p>I'm reading live555's <font face="monospace">UsageEnvironment</font>
related source codes. And I note that the implementation of <font
face="monospace">EventTriggerId</font> is <font
face="monospace">u_int32_t</font>, and every ID only has one bit
set on and others off. Now I have some questions (to the default
provided implementation of these classes):</p>
<p>(1). Does the default implementation can only handle different
event triggers no more than 32 at the same time?</p>
<p>(2). Since the implementation is <font face="monospace">u_int32_t</font>,
and <font face="monospace">TaskScheduler::TriggerEvent</font>
function may be called outside the event loop, is there any
thread-safety problem?</p>
<p>For question (2), I note that member variable <font
face="monospace">BasicTaskScheduler0::fTriggersAwaitingHandling</font>
can be modified both in and outside of the event loop. For
example, in the event loop <font face="monospace">BasicTaskScheduler::SingleStep</font>
may execute <font face="monospace">fTriggersAwaitingHandling
&=~ fLastUsedTriggerMask;</font> And in the <font
face="monospace">BasicTaskScheduler0::triggerEvent</font> (out
side the event loop) may execute <font face="monospace">fTriggersAwaitingHandling
|= eventTriggerId;</font> And from the view of assembly code, <font
face="monospace">|=</font> or <font face="monospace">&=</font>
operator consists of three steps:</p>
<p>1. Read the variable from memory into register; 2. Operate on the
register(<font face="monospace">|</font> or <font
face="monospace">&</font>); 3. Write register back to
variable memory.</p>
<p>BTW, the <font face="monospace">volatile </font>specifier
hasn't been ignored by me, but I don't think it can ensure the
atomic operation on variable<font face="monospace">
BasicTaskScheduler0::fTriggersAwaitingHandling</font>.</p>
<p>And also by the comment inside <font face="monospace">BasicTaskScheduler0::triggerEvent</font>:</p>
<blockquote>
<p><font face="monospace"> // Then, note this event as being
ready to be handled.<br>
// (Note that because this function (unlike others in the
library) can be called from an external thread, we do this
last, to<br>
// reduce the risk of a race condition.)<br>
fTriggersAwaitingHandling |= eventTriggerId;</font></p>
</blockquote>
<p>Can I understand it as: The risk of a race condition is reduced,
but it may ocurr under some circumstances.</p>
<p>I'll appreciate any explanation.<br>
<font face="monospace"></font></p>
</body>
</html>