<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<!--[if !mso]><style>v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style><![endif]--><style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri",sans-serif;
mso-fareast-language:EN-US;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:#0563C1;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:#954F72;
text-decoration:underline;}
span.EmailStyle17
{mso-style-type:personal-compose;
font-family:"Calibri",sans-serif;
color:windowtext;}
.MsoChpDefault
{mso-style-type:export-only;
font-family:"Calibri",sans-serif;
mso-fareast-language:EN-US;}
@page WordSection1
{size:612.0pt 792.0pt;
margin:3.0cm 2.0cm 3.0cm 2.0cm;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="DA" link="#0563C1" vlink="#954F72">
<div class="WordSection1">
<p class="MsoNormal"><span lang="EN-GB">Hi,<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">In the liveMedia FAQ section: ”Is this code 'thread safe'? I.e., can it be accessed by more than one thread at the same time?”, it is stated that:<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">“…Another possible way to access the code from multiple threads is to have each thread use its own "UsageEnvironment" and "TaskScheduler" objects, and thus its own event loop.”<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">I know that it is not recommended to use this approach, but I am working with an application that has been implemented that way and it has been working fine. However, I have stumbled upon an issue when investigating a
crash – see part of the back trace below.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">I suspect that the:<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">class DelayQueueEntry {<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">…<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">private:<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">…<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"> static intptr_t tokenCounter; <-----<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">};<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">might cause the crash due to something resembling the following sequence:<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">Thread1->…->new DelayQueueEntry(…)<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">Thread1-> DelayQueueEntry - read tokenCounter = 0<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">Thread1-> DelayQueueEntry - increment tokenCounter (1)<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">--- thread switch<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">Thread2->…-> new DelayQueueEntry(…)<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">Thread2-> DelayQueueEntry - read tokenCounter = 0<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">Thread2-> DelayQueueEntry - increment tokenCounter (1)<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">Thread2-> DelayQueueEntry - write tokenCounter = 1<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">Thread2->…-> new DelayQueueEntry(…)<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">Thread2-> DelayQueueEntry - read tokenCounter = 1<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">Thread2-> DelayQueueEntry - increment tokenCounter (2)<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">Thread2-> DelayQueueEntry - write tokenCounter = 2<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">--- thread switch<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">Thread1-> DelayQueueEntry - write tokenCounter = 1<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">--- thread switch<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">Thread2->…-> new DelayQueueEntry(…)<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">Thread2-> DelayQueueEntry - read tokenCounter = 1<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">Thread2-> DelayQueueEntry - increment tokenCounter (2)<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">Thread2-> DelayQueueEntry - write tokenCounter = 2<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">Such a sequence would result in reuse of a token within a single thread, which I suspect might be an issue that could lead to a crash.<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">Do you also see an issue here?<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">#0 0x00007ffdbc34b8c0 in ucrtbase!exit () …<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">…<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">#6 0x00007ffdc4b3921d in ntdll!.chkstk () from C:\Windows\SYSTEM32\ntdll.dll<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">#7 0x00007ffdc4af5b5b in ntdll!RtlAppendUnicodeToString () from C:\Windows\SYSTEM32\ntdll.dll<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">#8 0x00007ffdc4b383de in ntdll!KiUserExceptionDispatcher () from C:\Windows\SYSTEM32\ntdll.dll<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">#9 0x0000000028e9f89c in DelayQueue::addEntry (this=0x2fc03fa8, newEntry=0x3b0097f0) at DelayQueue.cpp:139<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-US">…<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB"><o:p> </o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:8.0pt;font-family:"Arial",sans-serif;color:#1F497D;mso-fareast-language:DA">Best Regards<o:p></o:p></span></p>
<p class="MsoNormal"><span lang="EN-GB" style="font-size:8.0pt;font-family:"Arial",sans-serif;color:#1F497D;mso-fareast-language:DA"><o:p> </o:p></span></p>
<p class="MsoNormal"><b><span lang="EN-GB" style="font-size:9.0pt;font-family:"Arial",sans-serif;color:#1F497D;mso-fareast-language:DA">Jan Rørgaard Hansen<o:p></o:p></span></b></p>
<p class="MsoNormal"><span lang="EN-US" style="font-size:8.0pt;font-family:"Arial",sans-serif;color:black;mso-fareast-language:DA">Lead Software Developer</span><span lang="EN-US" style="font-size:8.0pt;font-family:"Arial",sans-serif;color:#1F497D;mso-fareast-language:DA"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height:12.0pt;text-autospace:none"><span lang="EN-AU" style="font-size:8.0pt;font-family:"Arial",sans-serif;mso-fareast-language:DA">Communication Solutions<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height:12.0pt;text-autospace:none"><span lang="EN-AU" style="font-size:8.0pt;font-family:"Arial",sans-serif;mso-fareast-language:DA">Business Area Surveillance<i><o:p></o:p></i></span></p>
<p class="MsoNormal" style="line-height:12.0pt;text-autospace:none"><span lang="EN-US" style="font-size:8.0pt;font-family:"Arial",sans-serif;color:black;mso-fareast-language:DA"><o:p> </o:p></span></p>
<p class="MsoNormal" style="line-height:12.0pt;text-autospace:none"><span lang="EN-US" style="font-size:8.0pt;font-family:"Arial",sans-serif;color:black;mso-fareast-language:DA">Tel.: + 45 3638 3000<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height:12.0pt;text-autospace:none"><span lang="EN-GB" style="font-size:8.0pt;font-family:"Arial",sans-serif;color:#1F497D;mso-fareast-language:EN-GB">Call me on:
<a href="skype:jan.r.hansen@dk.saabgroup.com?call"><span style="color:blue">Skype</span></a></span><span lang="EN-US" style="font-size:8.0pt;font-family:"Arial",sans-serif;color:black;mso-fareast-language:DA"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height:12.0pt;text-autospace:none"><span lang="EN-US" style="font-size:8.0pt;font-family:"Arial",sans-serif;color:black;mso-fareast-language:DA">E-mail:
</span><span lang="EN-US" style="font-size:8.0pt;font-family:"Arial",sans-serif;mso-fareast-language:DA"><a href="mailto:jan.r.hansen@dk.saabgroup.com"><span style="color:blue">jan.r.hansen@dk.saabgroup.com</span></a><span style="color:black"><o:p></o:p></span></span></p>
<p class="MsoNormal" style="line-height:12.0pt;text-autospace:none"><span lang="EN-US" style="font-size:9.0pt;font-family:"Arial",sans-serif;color:black;mso-fareast-language:DA"><o:p> </o:p></span></p>
<p class="MsoNormal" style="line-height:12.0pt;text-autospace:none"><span lang="EN-US" style="font-size:9.0pt;font-family:"Arial",sans-serif;color:black;mso-fareast-language:DA"><o:p> </o:p></span></p>
<p class="MsoNormal" style="line-height:12.0pt;text-autospace:none"><span style="mso-fareast-language:DA"><img border="0" width="113" height="36" style="width:1.175in;height:.375in" id="Picture_x0020_1" src="cid:image001.jpg@01D925DE.09E74860" alt="Saab_rgb_150px"></span><span lang="EN-US" style="font-size:9.0pt;font-family:"Arial",sans-serif;color:black;mso-fareast-language:DA"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height:12.0pt;text-autospace:none"><span lang="EN-US" style="font-size:9.0pt;font-family:"Arial",sans-serif;color:black;mso-fareast-language:DA"><o:p> </o:p></span></p>
<p class="MsoNormal" style="line-height:12.0pt;text-autospace:none"><span lang="EN-US" style="font-size:9.0pt;font-family:"Arial",sans-serif;color:black;mso-fareast-language:DA"><o:p> </o:p></span></p>
<p class="MsoNormal" style="line-height:12.0pt;text-autospace:none"><span style="font-size:9.0pt;font-family:"Arial",sans-serif;color:black;mso-fareast-language:DA">Saab Danmark A/S<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height:12.0pt;text-autospace:none"><span style="font-size:8.0pt;font-family:"Arial",sans-serif;color:black;mso-fareast-language:DA">Porten 6<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height:12.0pt;text-autospace:none"><span style="font-size:8.0pt;font-family:"Arial",sans-serif;color:black;mso-fareast-language:DA">DK – 6400 Sonderborg
<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height:12.0pt;text-autospace:none"><span style="mso-fareast-language:DA"><a href="http://www.saabgroup.com/"><span lang="EN-US" style="font-size:8.0pt;font-family:"Arial",sans-serif;color:blue">www.saabgroup.com</span></a></span><span lang="EN-US" style="font-size:8.0pt;font-family:"Arial",sans-serif;color:black;mso-fareast-language:DA"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height:12.0pt;text-autospace:none"><span lang="EN-US" style="font-size:8.0pt;font-family:"Arial",sans-serif;color:black;mso-fareast-language:DA"><o:p> </o:p></span></p>
<p class="MsoNormal" style="line-height:12.0pt;text-autospace:none"><i><span lang="EN-US" style="font-size:8.0pt;font-family:"Arial",sans-serif;color:black;mso-fareast-language:DA">This e-mail is private and confidential between the sender and the addressee.
<o:p></o:p></span></i></p>
<p class="MsoNormal" style="line-height:12.0pt;text-autospace:none"><i><span lang="EN-US" style="font-size:8.0pt;font-family:"Arial",sans-serif;color:black;mso-fareast-language:DA">In the event of misdirection, the recipient is prohibited from using, copying
or <o:p></o:p></span></i></p>
<p class="MsoNormal" style="line-height:12.0pt;text-autospace:none"><i><span lang="EN-US" style="font-size:8.0pt;font-family:"Arial",sans-serif;color:black;mso-fareast-language:DA">disseminating it or information in it. Please notify the above if any misdirection.<o:p></o:p></span></i></p>
<p class="MsoNormal"><span lang="EN-GB"><o:p> </o:p></span></p>
</div>
</body>
</html>