Note that there are some explanatory texts on larger screens.

plurals
  1. POIs there a windows concurrency_queue.h equivalent on linux?
    primarykey
    data
    text
    <p>Well I am tryng to have a queue which is concurrent, but <a href="http://msdn.microsoft.com/en-us/library/ee355358.aspx" rel="nofollow">concurrency_queue</a> isn't standard C++ and it's for windows, linux doesn't have it. Is there anything for linux like this (with the same functions like in the windows equivalent?)?</p> <p>Edit: This is needed to port this windows code to linux:</p> <pre><code>#include &lt;concurrent_queue.h&gt; #ifdef defined(WIN32) || defined(_WIN32) || defined(__WIN32__) #define SLEEP(x) { Sleep(x); } #include &lt;windows.h&gt; #include &lt;process.h&gt; #define OS_WINDOWS #define EXIT_THREAD() { _endthread(); } #define START_THREAD(a, b) { _beginthread( a, 0, (void *)( b ) ); } #else #include &lt;pthread.h&gt; #define sscanf_s sscanf #define sprintf_s sprintf #define EXIT_THREAD() { pthread_exit( NULL ); } #define START_THREAD(a, b) { pthread_t thread;\ pthread_create( &amp;thread, NULL, a, (void *)( b ) ); } #endif using namespace std; using namespace Concurrency; struct QuedData { int start; int end; int extraid; AMX * script; QuedData(){start = 0;end = 0;extraid = 0;script = NULL;} QuedData(int start_,int end_,int extraid_, AMX * script_){start = start_;end = end_;extraid = extraid_;script = script_;} }; struct PassData //thanks to DeadMG for improvements. { std::vector&lt;cell&gt; Paths; int extraid; AMX * script; cell MoveCost; PassData(){extraid = 0;script = NULL;MoveCost = 0;Paths.clear();} template&lt;typename Iterator&gt; PassData(Iterator begin, Iterator end, int extraid_, cell MoveCost_, AMX * script_) : Paths(begin, end) {extraid = extraid_;MoveCost = MoveCost_;script = script_;} ~PassData(){Paths.clear();} }; concurrent_queue &lt;QuedData&gt; QueueVector; concurrent_queue &lt;PassData&gt; PassVector; PassData LocalPass; void PLUGIN_CALL ProcessTick() { if(PassVector.try_pop(LocalPass)) { amx_Push(LocalPass.script, LocalPass.MoveCost); //blabla } } static cell AMX_NATIVE_CALL n_CalculatePath( AMX* amx, cell* params ) { QueueVector.push(QuedData(params[1],params[2],params[3],amx)); return 1; } bool PLUGIN_CALL Load( void **ppData ) { START_THREAD( Thread::BackgroundCalculator, 0); return true; } QuedData RecievedData; vector &lt;cell&gt;tbcway; cell tbccostx; #ifdef OS_WINDOWS void Thread::BackgroundCalculator( void *unused ) #else void *Thread::BackgroundCalculator( void *unused ) #endif { while( true ){ if(QueueVector.try_pop(RecievedData)){ dgraph-&gt;findPath_r(xNode[RecievedData.start].NodeID ,xNode[RecievedData.end].NodeID,tbcway,tbccostx); PassVector.push(PassData(tbcway.begin(),tbcway.end(),RecievedData.extraid,tbccostx,RecievedData.script)); } SLEEP(5); } EXIT_THREAD(); } </code></pre>
    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.
    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