public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Proposed C++ extension
@ 2002-08-30 16:32 Niall Douglas
  2002-08-31  7:09 ` Nathan Sidwell
  0 siblings, 1 reply; 2+ messages in thread
From: Niall Douglas @ 2002-08-30 16:32 UTC (permalink / raw)
  To: gcc

Firstly, I'll apologise for not diving deep and producing a patch for 
g++. Last time I tried, I got very very lost ...

My suggestion is adding support for temporary object copy 
constructors - these differ from normal copy constructors in that 
when the object is being created by the compiler rather than the 
user, the temporary object copy constructor is called instead.

Why? Because C++ doesn't support multithreading very well. I have a 
number of implicitly shared classes for which I had to disable 
implicit sharing because of the potential of data corruption as it's 
impossible to synchronise all users of the implicit data without 
running through a mutex each time.

Unfortunately disabling implicit sharing creates performance problems 
in something like a string class. If we had a special copy 
constructor for temporary objects, we could do ptr copies for the 
temporary objects and the real copy constructor for the final object. 
Obviously, optimisation can decide when user created local objects 
are unnecessary, and hence optimise them into temporary land.

Anyway, if you were to add this, I'd stick the appropriate code into 
my implicitly shared-disabled classes. So would others I'm sure. 
String work would become much quicker.

The other suggestion is a precall and postcall handler whereby in 
every call to an object, the compiler wraps the call with the precall 
and postcall code. Again, it's use is for porting old code to become 
multithreading aware - but I can envisage other useful uses as well.

Anyway, those are my experiences from learning C++. I'm well into 
year three of learning it, but I'm still nowhere close to done!

Cheers,
Niall Douglas

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Proposed C++ extension
  2002-08-30 16:32 Proposed C++ extension Niall Douglas
@ 2002-08-31  7:09 ` Nathan Sidwell
  0 siblings, 0 replies; 2+ messages in thread
From: Nathan Sidwell @ 2002-08-31  7:09 UTC (permalink / raw)
  To: Niall Douglas; +Cc: gcc

Niall Douglas wrote:

> Why? Because C++ doesn't support multithreading very well. I have a
> number of implicitly shared classes for which I had to disable
> implicit sharing because of the potential of data corruption as it's
> impossible to synchronise all users of the implicit data without
> running through a mutex each time.
> 
> Unfortunately disabling implicit sharing creates performance problems
> in something like a string class. If we had a special copy
> constructor for temporary objects, we could do ptr copies for the
> temporary objects and the real copy constructor for the final object.
> Obviously, optimisation can decide when user created local objects
> are unnecessary, and hence optimise them into temporary land.
can't what you want be done with,

	class unique_t { ... };
	class shared_t : public unique_t {... locks in here };

	void somefunc (unique_t arg);
now a unique_t copy ctor is invoked.

your problem description is too vague. I can't tell if you want a magic
bullet which will make your program multithreadable, or if you want some way
of saying 'this is a unique object, no need to lock it'.

nathan
-- 
Dr Nathan Sidwell   ::   http://www.codesourcery.com   ::   CodeSourcery LLC
         'But that's a lie.' - 'Yes it is. What's your point?'
nathan@codesourcery.com : http://www.cs.bris.ac.uk/~nathan/ : nathan@acm.org

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2002-08-31  7:09 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-08-30 16:32 Proposed C++ extension Niall Douglas
2002-08-31  7:09 ` Nathan Sidwell

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).