Note that there are some explanatory texts on larger screens.

plurals
  1. POrun time exception raised in code
    primarykey
    data
    text
    <p>i am implementing one algorithm in which i have used thread library of CPP and Intel TBB Library for MultiCore.while i am calling function with the help of thread some times it executes perfectly and sometimes it gives run time exception.i am trying to find cause but couldn't find . Please find the code snippet example which is giving exception.</p> <pre><code>#include &lt;iostream&gt; #include &lt;sstream&gt; #include &lt;fstream&gt; #include &lt;vector&gt; #include &lt;algorithm&gt; #include &lt;tbb/pipeline.h&gt; #include &lt;tbb/atomic.h&gt; #include &lt;tbb/concurrent_queue.h&gt; #include &lt;tbb/compat/thread&gt; #include &lt;tbb/tbbmalloc_proxy.h&gt; using namespace std; using namespace tbb; #define pi 3.141593 #define FILTER_LEN 265 class MyBuffer { public: double *acc; double *buffer; int start,end; MyBuffer() { start=0; end=0; buffer=new double[150264]; acc=new double[150000]; fill_n(buffer,150264,0); } ~MyBuffer() { delete[] buffer; delete[] acc; } int startnumber() { return start; } int endnumber() { return end; } }; typedef concurrent_queue&lt;MyBuffer&gt; QueueMyBufferType; QueueMyBufferType chunk_queue; atomic&lt;bool&gt; stop_flag; // input function that will be running by thread to generate sinewave void input_function() { stop_flag = false; cout&lt;&lt;"thread reached to call input function " &lt;&lt;endl; ofstream o("testing sinewave.csv"); int counter=0; while(counter&lt;150000) { cout&lt;&lt;"value of counter is \t" &lt;&lt;counter &lt;&lt; endl; //MyBuffer *b=new MyBuffer; MyBuffer b; b.start=(FILTER_LEN-1+(counter)); b.end=(25264+(counter)); cout&lt;&lt;"value of b.start is and b.end is "&lt;&lt;b.start&lt;&lt;"\t" &lt;&lt;b.end&lt;&lt;endl; for(int i =b.startnumber(); i &lt;b.endnumber(); i++) { b.buffer[i] = sin(700 * (2 * pi) * (i / 5000.0)); o&lt;&lt;b.buffer[i]&lt;&lt;endl; } chunk_queue.push(b); cout&lt;&lt;"object pushed in queue and value of j is \t" &lt;&lt;counter &lt;&lt;endl; counter+=25000; } stop_flag = true; cout&lt;&lt;"all data is perfectly generated" &lt;&lt;endl; } int main() { thread input_thread(input_function); while(!stop_flag) { //cout&lt;&lt;"waiting for thread " &lt;&lt; endl; } cout &lt;&lt; "\n All Data is processed \n\n" &lt;&lt; endl; return 0; } </code></pre> <p>This code is part of application and helps in generating sine wave .Please help to find where i am getting wrong.</p>
    singulars
    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.
    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