This is the mail archive of the ecos-discuss@sources.redhat.com mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: CONDITION VARIABLES & MUTEXES


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]