Search code examples
c++multithreadinglockingwxwidgets

wxWidgets and locking resources


I'm new to wxWidgets (C++), and threads for that matter. What should I be aware of concerning shared resources? Should I implement some sort of semaphore-based locking of resources that may be used by both the GUI thread and the worker thread(s)? Does wxWidgets offer some capability for dealing with this?


Solution

  • Not sure what your choice of threading library is at this point but in your case I'd use wxThread (see here & here for documentation).

    What should I be aware of concerning shared resources?

    See the Important notes for multithreaded applications part here for wxWidgets specific multi-threading issues.
    Other than that the 'usual' concerns about shared resources apply.

    Should I implement some sort of semaphore-based locking of resources that may be used by both the GUI thread and the worker thread(s)? Does wxWidgets offer some capability for dealing with this?

    wxWidgets already implements a number of synchronization objects, see here.
    As a side note prefer using the RAII locker helpers (wxMutexLocker, wxCriticalSectionLocker) instead of explicitly acquiring/releasing.