[Live-devel] Possible issue in DelayQueue

Hansen Jan Rørgård jan.r.hansen at dk.saabgroup.com
Wed Jan 11 07:59:17 PST 2023


Hi,

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:
"...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."

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.

I suspect that the:
class DelayQueueEntry {
...
private:
...
  static intptr_t tokenCounter;    <-----
};
might cause the crash due to something resembling the following sequence:

Thread1->...->new DelayQueueEntry(...)
Thread1-> DelayQueueEntry - read tokenCounter = 0
Thread1-> DelayQueueEntry - increment tokenCounter (1)
--- thread switch
Thread2->...-> new DelayQueueEntry(...)
Thread2-> DelayQueueEntry - read tokenCounter = 0
Thread2-> DelayQueueEntry - increment tokenCounter (1)
Thread2-> DelayQueueEntry - write tokenCounter = 1
Thread2->...-> new DelayQueueEntry(...)
Thread2-> DelayQueueEntry - read tokenCounter = 1
Thread2-> DelayQueueEntry - increment tokenCounter (2)
Thread2-> DelayQueueEntry - write tokenCounter = 2
--- thread switch
Thread1-> DelayQueueEntry - write tokenCounter = 1
--- thread switch
Thread2->...-> new DelayQueueEntry(...)
Thread2-> DelayQueueEntry - read tokenCounter = 1
Thread2-> DelayQueueEntry - increment tokenCounter (2)
Thread2-> DelayQueueEntry - write tokenCounter = 2

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.
Do you also see an issue here?

#0  0x00007ffdbc34b8c0 in ucrtbase!exit () ...
...
#6  0x00007ffdc4b3921d in ntdll!.chkstk () from C:\Windows\SYSTEM32\ntdll.dll
#7  0x00007ffdc4af5b5b in ntdll!RtlAppendUnicodeToString () from C:\Windows\SYSTEM32\ntdll.dll
#8  0x00007ffdc4b383de in ntdll!KiUserExceptionDispatcher () from C:\Windows\SYSTEM32\ntdll.dll
#9  0x0000000028e9f89c in DelayQueue::addEntry (this=0x2fc03fa8, newEntry=0x3b0097f0) at DelayQueue.cpp:139
...

Best Regards

Jan Rørgaard Hansen
Lead Software Developer
Communication Solutions
Business Area Surveillance

Tel.:  + 45 3638 3000
Call me on: Skype<skype:jan.r.hansen at dk.saabgroup.com?call>
E-mail: jan.r.hansen at dk.saabgroup.com<mailto:jan.r.hansen at dk.saabgroup.com>


[Saab_rgb_150px]


Saab Danmark A/S
Porten 6
DK - 6400 Sonderborg
www.saabgroup.com<http://www.saabgroup.com/>

This e-mail is private and confidential between the sender and the addressee.
In the event of misdirection, the recipient is prohibited from using, copying or
disseminating it or information in it. Please notify the above if any misdirection.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.live555.com/pipermail/live-devel/attachments/20230111/d041adee/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image001.jpg
Type: image/jpeg
Size: 1998 bytes
Desc: image001.jpg
URL: <http://lists.live555.com/pipermail/live-devel/attachments/20230111/d041adee/attachment.jpg>


More information about the live-devel mailing list