This is the mail archive of the
ecos-discuss@sources.redhat.com
mailing list for the eCos project.
Re: CONDITION VARIABLES & MUTEXES
- To: Srinivasan Sriram <pet_jimmy at yahoo dot com>
- Subject: Re: [ECOS] CONDITION VARIABLES & MUTEXES
- From: Robin Farine <acnrf at dial dot eunet dot ch>
- Date: 20 Jun 2001 19:28:00 +0200
- Cc: Jonathan Larmour <jlarmour at redhat dot com>, ecos-discuss at sourceware dot cygnus dot com
- References: <20010620072709.95589.qmail@web14008.mail.yahoo.com>
Srinivasan Sriram <pet_jimmy@yahoo.com> writes:
[...]
> cyg_user_start()
> {
>
> cyg_thread_create(1,fthr1,(cyg_addrword_t)0,"THREADA",(void
> *)stack[0],4096,&hthr1,&thr[0]);
>
> cyg_thread_create(2,fthr2,(cyg_addrword_t)0,"THREADB",(void
> *)stack[1],4096,&hthr2,&thr[1]);
>
> cyg_thread_create(1,fthr3,(cyg_addrword_t)0,"THREADC",(void
> *)stack[2],4096,&hthr3,&thr[2]);
> cyg_thread_resume(hthr1);
> cyg_thread_resume(hthr2);
> cyg_thread_resume(hthr3);
> cyg_mutex_init(&mut);
> cyg_cond_init(&cond,&mut);
Bug here, you should initialize the mutex and condition variable *before* using
them, i.e. before starting the threads!
[...]
>
> WHY DO WE REQUIRE THE WHILE LOOP? ANY WAY THE
> CYG_COND_WAIT CANNOT PROCEED BEFORE IT OBTAINS THE
> MUTEX AND BROADCAST FROM THE PRODUCER AND OTHER
> THREADS?
>
> ALSO COULD ANYONE EXPLAIN - WHAT IS THE VARIABLE IN
> THE WHILE LOOP. WHAT DOES IT TEST?
>
Friendly advice: read some articles or books on this subject (threads,
semaphores, condition variables,.) or get ready for big troubles (such as
race-conditions, dead-locks,. not the easiest bugs to find out).