public inbox for ecos-discuss@sourceware.org
 help / color / mirror / Atom feed
* [ECOS] Thread Creation
@ 2000-09-22  4:28 Sandeep Rikhi
  2000-11-06 21:00 ` Jonathan Larmour
  0 siblings, 1 reply; 8+ messages in thread
From: Sandeep Rikhi @ 2000-09-22  4:28 UTC (permalink / raw)
  To: eCos Discussion Gp.

Respected Sir

I'm not able to understand
a few points in eCos 1.2.1 source code.
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.

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 ?
 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.
 3. Also, what is the significance of the statement
    t=t; Isn't redundant ?
Sir, The above three doubts are very much generic, I would
   say. e.g. Similar is the case when a messagebox is created
   through the cyg_mbox_create API call.

Kindly Help !

********Sandeep Rikhi *******************


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

* Re: [ECOS] Thread Creation
  2000-09-22  4:28 [ECOS] Thread Creation Sandeep Rikhi
@ 2000-11-06 21:00 ` Jonathan Larmour
  0 siblings, 0 replies; 8+ messages in thread
From: Jonathan Larmour @ 2000-11-06 21:00 UTC (permalink / raw)
  To: Sandeep Rikhi; +Cc: eCos Discussion Gp.

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

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

* Re: [ECOS] thread creation
  2004-09-14 12:17 [ECOS] thread creation Aravind B
@ 2004-09-14 12:27 ` Gary Thomas
  0 siblings, 0 replies; 8+ messages in thread
From: Gary Thomas @ 2004-09-14 12:27 UTC (permalink / raw)
  To: Aravind B; +Cc: ecos

On Tue, 2004-09-14 at 06:17, Aravind B wrote:
> hi all,
> i have written small application which has  2 threads.
> small part of it is as follows:
> void cyg_user_start(void)
> {
> 	printf("entering two threads cyg_user_start() function\n");
> 	cyg_thread_create(4,simple_program,(cyg_addrword_t)0,
> 			  "Thread A",(void*) stack[0],4096,
> 			  &simple_threadA,&thread_s[0]);
> 	cyg_thread_create(5,simple_program1,(cyg_addrword_t)1,
> 			 "Thread B",(void*) stack[1],4096,
> 			 &simple_threadB,&thread_s[1]);
> cyg_thread_resume(simple_threadA);
> cyg_thread_resume(simple_threadB);
> }
> when the control comes for execution of second thread the system hangs.
> on debug i found that the control is in thread.cxx.
> why is this happening and how to overcome this.

Given the terseness of your description, it's hard to tell exactly
what the problem is.  First guess is that stack[0] and stack[1]
don't contain actual stack pointers.

Have you run this code with asserts (kernel debugging) enabled?

-- 
Gary Thomas <gary@mlbassoc.com>
MLB Associates


-- 
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss

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

* [ECOS] thread creation
@ 2004-09-14 12:17 Aravind B
  2004-09-14 12:27 ` Gary Thomas
  0 siblings, 1 reply; 8+ messages in thread
From: Aravind B @ 2004-09-14 12:17 UTC (permalink / raw)
  To: ecos

hi all,
i have written small application which has  2 threads.
small part of it is as follows:
void cyg_user_start(void)
{
	printf("entering two threads cyg_user_start() function\n");
	cyg_thread_create(4,simple_program,(cyg_addrword_t)0,
			  "Thread A",(void*) stack[0],4096,
			  &simple_threadA,&thread_s[0]);
	cyg_thread_create(5,simple_program1,(cyg_addrword_t)1,
			 "Thread B",(void*) stack[1],4096,
			 &simple_threadB,&thread_s[1]);
cyg_thread_resume(simple_threadA);
cyg_thread_resume(simple_threadB);
}
when the control comes for execution of second thread the system hangs.
on debug i found that the control is in thread.cxx.
why is this happening and how to overcome this.

thanking advance.

Aravind B 



-- 
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss

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

* Re: [ECOS] THread creation
  2001-04-10 14:45 [ECOS] THread creation Paleologos Spanos
@ 2001-04-10 23:36 ` Jesper Skov
  0 siblings, 0 replies; 8+ messages in thread
From: Jesper Skov @ 2001-04-10 23:36 UTC (permalink / raw)
  To: Paleologos Spanos; +Cc: ecos-discuss

>>>>> "Paleologos" == Paleologos Spanos <paleolog@ee.ucla.edu> writes:

Paleologos>  HI,I have a question concerning the creation of threads
Paleologos> in eCos.THe reference manual says that first I have to
Paleologos> create the threads and then starts the scheduler and never
Paleologos> returns.Does it mean that I can not create new threads
Paleologos> after the scheduler starts ?  How can I create dynamically
Paleologos> new threads after the scheduler starts?

No, it means you cannot create new threads from the function where you
start the scheduler - it runs in a single-thread environment, if you
will, which is replaced by the scheduler system letting only
registered threads run.

To create new threads on the fly, create them from other threads.

For an example, see something like the tm_basic test. I'm pretty sure
it does something like this.

Jesper

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

* Re: [ECOS] Thread creation
  2001-04-10 15:42 [ECOS] Thread creation Paleologos Spanos
@ 2001-04-10 18:11 ` Jonathan Larmour
  0 siblings, 0 replies; 8+ messages in thread
From: Jonathan Larmour @ 2001-04-10 18:11 UTC (permalink / raw)
  To: Paleologos Spanos; +Cc: ecos-discuss

Paleologos Spanos wrote:
> 
>  HI,I have a question concerning the creation of threads in eCos.THe
> reference manual says that first I have to create the threads and then
> starts the scheduler which never returns.Does it mean that I can not
> create new threads after the scheduler starts ?
>  How can I create dynamically new threads after the scheduler starts?

Create them from the threads you just started!

Jifl
-- 
Red Hat, Rustat House, Clifton Road, Cambridge, UK. Tel: +44 (1223) 271062
Maybe this world is another planet's Hell -Aldous Huxley || Opinions==mine

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

* [ECOS] Thread creation
@ 2001-04-10 15:42 Paleologos Spanos
  2001-04-10 18:11 ` Jonathan Larmour
  0 siblings, 1 reply; 8+ messages in thread
From: Paleologos Spanos @ 2001-04-10 15:42 UTC (permalink / raw)
  To: ecos-discuss

 HI,I have a question concerning the creation of threads in eCos.THe
reference manual says that first I have to create the threads and then
starts the scheduler which never returns.Does it mean that I can not
create new threads after the scheduler starts ?
 How can I create dynamically new threads after the scheduler starts?

                                   Thank you.


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

* [ECOS] THread creation
@ 2001-04-10 14:45 Paleologos Spanos
  2001-04-10 23:36 ` Jesper Skov
  0 siblings, 1 reply; 8+ messages in thread
From: Paleologos Spanos @ 2001-04-10 14:45 UTC (permalink / raw)
  To: ecos-discuss

 HI,I have a question concerning the creation of threads in eCos.THe
reference manual says that first I have to create the threads and then
starts the scheduler and never returns.Does it mean that I can not create
new threads after the scheduler starts ?
 How can I create dynamically new threads after the scheduler starts?

                                   Thank you.

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

end of thread, other threads:[~2004-09-14 12:27 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-09-22  4:28 [ECOS] Thread Creation Sandeep Rikhi
2000-11-06 21:00 ` Jonathan Larmour
2001-04-10 14:45 [ECOS] THread creation Paleologos Spanos
2001-04-10 23:36 ` Jesper Skov
2001-04-10 15:42 [ECOS] Thread creation Paleologos Spanos
2001-04-10 18:11 ` Jonathan Larmour
2004-09-14 12:17 [ECOS] thread creation Aravind B
2004-09-14 12:27 ` Gary Thomas

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).