Note that there are some explanatory texts on larger screens.

plurals
  1. POSegfault accessing classes across threads
    primarykey
    data
    text
    <p>I'm a bit stumped on an issue I'm having with threading and C++. I'm writing a DSP plugin for Windows Media Player, and I want to send the data I intercept to a separate thread where I'll send it out on the network. I'm using a simple producer-consumer queue like the one explained <a href="http://msmvps.com/blogs/vandooren/archive/2007/01/05/creating-a-thread-safe-producer-consumer-queue-in-c-without-using-locks.aspx" rel="nofollow">here</a> </p> <p>The program is crashing on the isFull() function which just compares two integers:</p> <pre><code>bool ThreadSafeQueue::isFull() { if (inCount == outCount) //CRASH! return true; else return false; } </code></pre> <p>The thread that's doing the dequeuing:</p> <pre><code>void WMPPlugin::NetworkThread (LPVOID pParam) { ThreadSafeQueue* dataQueue = (ThreadSafeQueue*)(pParam); while (!networkThreadDone) { Sleep(2); /// so we don't hog the processor or make a race condition if (!dataQueue-&gt;isFull()) short s = dataQueue-&gt;dequeue(); if (networkThreadDone) // variable set in another process so we know to exit break; } } </code></pre> <p>The constructor of the class that's creating the consumer thread:</p> <pre><code>WMPPlugin::WMPPlugin() { // etc etc dataQueue = new ThreadSafeQueue(); _beginthread(WMPPlugin::NetworkThread, 0, dataQueue); } </code></pre> <p>inCount and outCount are just integers and they're only read here, not written. I was under the impression this meant they were thread safe. The part that writes them aren't included, but each variable is only written to by one thread, never by both. I've done my best to not include code that I don't feel is the issue, but I can include more if necessary. Thanks in advance for any help.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload