Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3271920
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T18:46:29+00:00 2026-05-17T18:46:29+00:00

I recently read the Head First Design Patterns book and I especially liked how

  • 0

I recently read the Head First Design Patterns book and I especially liked how the chapter on MVC seemed to bring everything together from the previous chapters. However, I am now on the verge of implementing a MVC pattern (using wxWidgets in C++) and I am beginning to realize that I don’t understand threading issues as much as I should.

I have a View that must be updated continuously as the Model changes, however, a user can interact with the Control and also affect the Model. Since the View/Control and the Model will be running in 2 different threads (or is it 3?), how do I ensure that I don’t have two threads writing to the same data object? Am I responsible for setting up locks on the shared data? Or am I just somehow guaranteed to not have any problems as long as I use the events framework properly?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T18:46:30+00:00Added an answer on May 17, 2026 at 6:46 pm

    MVC was thought up originally for message based systems (Smalltalk), what in a sense is an opposite to multi-threading.

    Best (theoretical) way known to me how to marry the MVC and multi-threading is the active object (or actor) concept: the object lives in its own threads, can send/receive messages/events to other active objects. That assumes that all actions on the object are synchronized – since single objects is bound to a single thread – what is analogue of a per-object mutex.

    I have a View that must be updated continuously as the Model changes, however, a user can interact with the Control and also affect the Model. Since the View/Control and the Model will be running in 2 different threads (or is it 3?),

    I have no experience with wxWidgets, but generally GUI part of an application is single-threaded (apparently valid for wxWidgets too), running exclusively in the main thread.

    View and Controller are UI bound, thus have to run in the main thread. With extra thread for the Model that makes it 2.

    how do I ensure that I don’t have two threads writing to the same data object?

    Per-object mutex.

    Am I responsible for setting up locks on the shared data?

    Yes.

    Or am I just somehow guaranteed to not have any problems as long as I use the events framework properly?

    No. As mentioned above, GUI is single-threaded. If you start you own threads, then you have to take care of the synchronization.

    If from the main/GUI thread you trigger an action in other thread, then obviously you need to synchronize the access to the shared data. If other thread wants to access GUI, then you have to use special functions (mentioned in the linked article) to trigger events in the main GUI thread (e.g. Model was updated in background threads, View has to redraw it in the main thread).

    If background thread is updating continuously the Model, then obviously special care has to be taken that the thread doesn’t keep the mutex locked all the time so that the main thread, GUI, where View runs can access the model too. (Some sort of readers-writer lock is desirable.) Controller has to be disabled, since if application does something in the background, user interaction might be undesirable.

    Overall, I think it is better to keep the MVC in the main thread. GUI thread doesn’t generate much of CPU load and oftentimes the idle events (wx has them too) are sufficient to simulate background job.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I recently read about the Dependency-Inversion Principal in Robert.C.Martin's excellent book Agile Principals, Patterns
I recently read Michael C. Feathers' book Working effectively with legacy code and came
I recently read an article on Wikipedia about Design Pattern So far I've done
I recently read about Dynamic Creation as one of the design pattern in Cocoa.
I recently read a paper that compared Design-by-Contract to Test-Driven-Development. There seems to be
I've read the whole Dragon Book recently (just for fun, I'm not really planning
Recently read this SO Post ...first answer is nutz. Basically it is theoretically impossible
I recently read an article about password hashing . How are MD5 or SHA1
I recently read a blog in Nodejitsu and I am wondering how this piece
I recently read a post online about rotating text with css. This appealed to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.