Click here to Skip to main content
15,887,862 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I've heard that GUIs are generally not thread-safe, and this seems to be true across multiple GUI libraries (such as MFC and WinForms, for instance). I have seen crashing or odd behavior caused simply by updating some text on a GUI object from a separate thread. Why are even the simplest GUI operations generally not thread-safe? Is there something inherent about GUIs that make them not thread-safe? Or rather, why do so few GUI libraries claim to be thread-safe?
Posted

The answer is really simple: cost and legacy. Thread safety is really resource costly. At the beginnings of windows and even win32 there was no real need to be thread-safe. Neither could I say today that most application do use this feature. In most cases you can reduce the usage of such tools to a minimum just by doing some organisation of your code and logic - and following best practices.
So, I think it is most likely a good approach to let coders decide when to use these features, than spending wealth of resources on nothing.

The problem with MFC is, that it can hardly evolve. It would use the strength, if such resource-costly things would become default. Thus you will miss some really fancy features, that are already present in other frameworks and languages...

In .net, at least, with features like anonymous delegates and lambda expressions, I think it is really not hard to do it, when needed (see this good article[^]). It could be even more simple - perhaps it will be in the future, but that's a matter of syntax or language tools, not of making everything thread-safe by default.
 
Share this answer
 
Performance is the reason, I suppose.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900