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   |
 |
mirek
Messages: 14255 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?" I would prefer using the data instead of pointer.
|
The answer is simple: U++ already uses the same idiom . 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
|
|
|
 |
|
Sharing and Locking
By: gridem on Sun, 07 March 2010 09:27
|
 |
|
Re: Sharing and Locking
By: mirek on Sun, 07 March 2010 14:40
|
 |
|
Re: Sharing and Locking
By: gridem on Sun, 07 March 2010 16:38
|
 |
|
Re: Sharing and Locking
By: mirek on Mon, 08 March 2010 01:42
|
 |
|
Re: Sharing and Locking
By: gridem on Mon, 08 March 2010 10:57
|
 |
|
Re: Sharing and Locking
By: gridem on Sun, 14 March 2010 13:37
|
 |
|
Re: Sharing and Locking
By: mirek on Sun, 14 March 2010 18:58
|
 |
|
Re: Sharing and Locking
By: gridem on Mon, 15 March 2010 21:26
|
 |
|
Re: Sharing and Locking
By: mirek on Tue, 16 March 2010 06:02
|
 |
|
Re: Sharing and Locking
By: gridem on Tue, 16 March 2010 08:04
|
 |
|
Re: Sharing and Locking
By: mirek on Tue, 16 March 2010 23:50
|
 |
|
Re: Sharing and Locking
By: gridem on Fri, 19 March 2010 07:44
|
 |
|
Re: Sharing and Locking
By: mirek on Fri, 19 March 2010 07:59
|
 |
|
Re: Sharing and Locking
By: gridem on Sat, 20 March 2010 10:21
|
 |
|
Re: Sharing and Locking
By: mirek on Sun, 21 March 2010 07:37
|
 |
|
Re: Sharing and Locking
By: gridem on Sun, 21 March 2010 11:39
|
 |
|
Re: Sharing and Locking
By: mirek on Sun, 21 March 2010 14:21
|
 |
|
Re: Sharing and Locking
By: gridem on Thu, 01 April 2010 09:14
|
 |
|
Re: Sharing and Locking
By: mirek on Tue, 16 March 2010 06:14
|
Goto Forum:
Current Time: Sun Apr 27 08:16:04 CEST 2025
Total time taken to generate the page: 0.02495 seconds
|