Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Community » Coffee corner » Sharing and Locking
Re: Sharing and Locking [message #25872 is a reply to message #25859] Tue, 16 March 2010 23:50 Go to previous messageGo to previous message
mirek is currently offline  mirek
Messages: 13984
Registered: November 2005
Ultimate Member
gridem wrote on Tue, 16 March 2010 03:04

luzr wrote on Tue, 16 March 2010 08:02


I would stop right there and asked "why?" Smile I would prefer using the data instead of pointer.


The answer is simple: U++ already uses the same idiom Smile. See for example:
CtrlCore.h:

	static  Ptr<Ctrl> focusCtrl;
	static  Ptr<Ctrl> focusCtrlWnd;
	static  Ptr<Ctrl> lastActiveWnd;
	static  Ptr<Ctrl> caretCtrl;




But these are to solve hard to predict user inputs. In most cases where MT threads are involved, you have much better control than that.


Quote:


No, the considered situation is a bit more complicated. Because I used not shared_ptr for global variable but weak_ptr, the object will live until it will be destroyed in thread 1. But if I was successfull on converting from weak_ptr to shared_ptr, than the object lifetime will be longer and will be destroyed when loop in thread 1 and thread 2 will be restarted. In any case the object will not be in partial (or zombie) state when it will be destoyed in destructor instead of some method like Close, Destroy or other.



Well, that is not what I mean. What is bad about shared ownership is exactly that it makes the lifetime of object unpredictable.

Quote:


The problems may occurs when I want to create the real MT application without GUI and try to access to global variables or global list of variables through Ptr.


Which is something to avoid, I agree...

Mirek
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Windows 7 - long wait after app crash
Next Topic: Upp application and CPU on Linux
Goto Forum:
  


Current Time: Thu Jun 06 08:33:44 CEST 2024

Total time taken to generate the page: 0.01809 seconds