Menu

#87 _ClassType_helper::_getStaticClassData() is not thead safe

None
closed
nobody
None
5
2015-04-27
2015-04-23
zenden2k
No

Add optional mutex here

static SQRAT_API WeakPtr<AbstractStaticClassData>& _getStaticClassData(const std::type_info* type) {
        static std::map<const std::type_info*, WeakPtr<AbstractStaticClassData>, compare_type_info> data;
        return data[type];
    }

Discussion

  • Wizzard

    Wizzard - 2015-04-27

    There's a lot more to making Sqrat thread-safe than just this.
    Please feel free to submit a patch that covers all edge cases.
    However, just adding a mutex in this one spot won't fix anything.

     
  • Wizzard

    Wizzard - 2015-04-27
    • status: open --> closed
    • Group: -->
     
  • zenden2k

    zenden2k - 2015-04-27

    Anyway I see much progress in multithread and multi-vm support.
    sqrat 0.8 had a lot of static variables.
    After I migrated to 0.9 _getStaticClassData() crashed my program.
    Adding a mutex fixed crashes. What else should be done?
    Is it possible to remove all static variables?

     

    Last edit: zenden2k 2015-04-27
  • Wizzard

    Wizzard - 2015-04-27

    Multiple VMs are supported. Multi-threading is not currently supported.
    The possibility of multi-threading has existed since commit [1f1061].
    In that commit, many bugs with having multiple VMs were fixed.
    However, all data that is shared between VMs is never locked.
    Sqrat has never locked this data, and it is necessary to be for multi-threading.
    You fixed a common race condition, but need to prevent a lot more.
    Basically, any time Sqrat is getting or setting shared data, it needs to be atomic.
    You can fix with locks and unlocks or another mechanism.
    If you make it in a way that is generic and conditional, I will accept your patch.
    However, know that this migrating likely just made multithreading crash more.
    Race conditions have always existed in Sqrat.
    About removing static variables, this is not possible without overhauling the API.
    Please also be aware that references to the same C++ data will crash the app.

     

    Related

    Commit: [1f1061]


    Last edit: Wizzard 2015-04-27

Log in to post a comment.

MongoDB Logo MongoDB