This is the mail archive of the
ecos-discuss@sources.redhat.com
mailing list for the eCos project.
Re: Thread Creation
- To: Sandeep Rikhi <sr at cdotb dot ernet dot in>
- Subject: Re: [ECOS] Thread Creation
- From: Jonathan Larmour <jlarmour at cygnus dot co dot uk>
- Date: Tue, 07 Nov 2000 04:58:51 +0000
- CC: "eCos Discussion Gp." <ecos-discuss at sourceware dot cygnus dot com>
- Organization: Red Hat UK Ltd.
- References: <Pine.OSF.4.21.0009221648030.24733-100000@ws9.cdotb.ernet.in>
Sandeep Rikhi wrote:
>
> Respected Sir
>
> I'm not able to understand
> a few points in eCos 1.2.1 source code.
eCos 1.2.1 is old by the way. 1.3.1 is out.
> May I request you to put some light on the the
> following :-
>
> Supposedly I create a thread through API call
>
> cyg_thread_create(. . . )
>
> which requires address of an object of cyg_thread
> structure ( i.e. cyg_thread * thread) , along with
> other parameters. The data members of the class
> Cyg_Thread contain the data memebers of the
> structure cyg_thread. I don't understand, how
> exactly are they related.
They are equivalent. We abuse the type system to provide equivalence
between a C cyg_thread type, and the C++ Cyg_Thread type.
> Now the code inside cyg_thread_create (file name kapi.cxx)
> is having the following statements :-
>
> Cyg_Thread * t = new ((void *) thread ) Cyg_Thread(
> (CYG_ADDRWORD) sched_info,
> (cyg_thread_entry *) entry,
> (CYG_ADDRWORD) entry_data,
> name,
> (CYG_ADDRWORD) stack_base,
> stack_size);
> t=t;
>
> Now, I have three doubts
> 1. Which of the various overloaded new operators is
> being used and what exactly does it do ?
This is what is called a placement new operator. It is defined near the top
of kapi.cxx as:
//
-------------------------------------------------------------------------
// Magic new function
inline void *operator new(size_t size, void *ptr)
{
CYG_CHECK_DATA_PTR( ptr, "Bad pointer" );
return ptr;
}
The concept is part of standard C++.
> 2. In new operator we are making a call to a constructor.
> How can we make a call to the constructor of a
> class i.e. Cyg_Thread class. Traditionally, we
> can not make explicit call to a constructor.
This is fairly standard C++. It's just instantiation of an object with
constructor parameters, in combination with a placement new operator.
> 3. Also, what is the significance of the statement
> t=t; Isn't redundant ?
It's to stop the compiler warning you that the variable isn't used.
Jifl
--
Red Hat, 35 Cambridge Place, Cambridge, UK. CB2 1NS Tel: +44 (1223) 728762
"Plan to be spontaneous tomorrow." || These opinions are all my own fault