Note that there are some explanatory texts on larger screens.

plurals
  1. POBdb crashes on concurrent write, c++ linux/osx
    primarykey
    data
    text
    <p>I am having issues with bdb and there locking mechanisms.</p> <p>The following code results in either a seg fault, or what looks like a deadlock/endless loop</p> <pre><code>#include &lt;iostream&gt; #include "db_cxx.h" #include &lt;boost/thread.hpp&gt; using namespace std; void thread_instance(Db* db, double start){ double s = start; double finish = start + 5000; for(int x=s; x &lt; finish ; x++){ Dbt key(&amp;x, sizeof(double)); Dbt ddata(&amp;x, sizeof(double)); db-&gt;put(NULL, &amp;key, &amp;ddata, 0); } } int compare_double(DB *dbp, const DBT *a,const DBT *b){ double ai, bi; memcpy(&amp;ai, a-&gt;data, sizeof(double)); memcpy(&amp;bi, b-&gt;data, sizeof(double)); return (ai &gt; bi ? 1 : ((ai &lt; bi) ? -1 : 0)); } int main(){ system("rm data/*"); u_int32_t env_flags = DB_CREATE | DB_INIT_MPOOL | DB_INIT_CDB; DbEnv* env = new DbEnv(0); env-&gt;set_cachesize(0, 2000000, 1); u_int32_t m = 0; env-&gt;open("data/", env_flags, 0); Db* db = new Db(env, 0); db-&gt;set_bt_compare(compare_double); db-&gt;set_flags(DB_DUPSORT); db-&gt;set_pagesize(32768); db-&gt;set_dup_compare(compare_double); u_int32_t oFlags = DB_CREATE; try { db-&gt;open(NULL, "db", NULL, DB_BTREE, oFlags, 0); } catch (DbException &amp;e) { } catch (std::exception &amp;e) { } vector&lt;boost::thread*&gt; threads; for(int x=0; x &lt; 3; x++){ threads.push_back(new boost::thread(boost::bind(&amp;thread_instance, db, (x *5000)))); } for(int x=0; x &lt; threads.size(); x++){ threads[x]-&gt;join(); } }; </code></pre> <p>I have tried DB_INIT_LOCK as well, but with the same results.</p> <p>The stack track:</p> <pre><code>Program received signal EXC_BAD_ACCESS, Could not access memory. Reason: KERN_INVALID_ADDRESS at address: 0x0000000000000019 [Switching to process 34816] 0x00000001002e36a7 in __bamc_put () (gdb) ba #0 0x00000001002e36a7 in __bamc_put () #1 0x0000000100386689 in __dbc_iput () #2 0x0000000100387a6c in __dbc_put () #3 0x0000000100383092 in __db_put () #4 0x0000000100397888 in __db_put_pp () #5 0x00000001002cee59 in Db::put () #6 0x0000000100001f88 in thread_instance (db=0x1007006c0, start=5000) at src/main.cpp:16 #7 0x0000000100698254 in thread_proxy () #8 0x00007fff80cb9456 in _pthread_start () #9 0x00007fff80cb9309 in thread_start () </code></pre> <p>Does anyone know what could be going on here ? </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.
    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