[ECOS] A query regarding cyg_mutex_lock in ecos-2.0

Bart Veer bartv@ecoscentric.com
Tue Mar 15 03:28:00 GMT 2005

>>>>> "Santanu" == Santanu Chatterjee <thisissantanu@gmail.com> writes:


    Santanu> Now, in the example programs that are supplied with eCos distribution, 
    Santanu> I was experimenting with the program twothreads.c. There it says:
    Santanu> (In cyg_user_start( )):
    Santanu> -----------------------------
    Santanu> /* and now a mutex to protect calls to the C library */
    Santanu> cyg_mutex_t cliblock;
    Santanu> ------------------------------
    Santanu> And in simple_program( ) thread:
    Santanu> ------------------------------
    Santanu>     /* note: printf() must be protected by a
    Santanu>        call to cyg_mutex_lock() */
    Santanu>     cyg_mutex_lock(&cliblock); {
    Santanu>       printf("Thread %d: and now a delay of %d clock ticks\n",
    Santanu>              message, delay);
    Santanu>     }
    Santanu> -------------------------------
    Santanu> I am not sure what exactly is being protected by the
    Santanu> mutex. Is it protecting all calls to the C library (If
    Santanu> so, how), or is it just an example showing how to
    Santanu> serialize access to a critical region of code? For
    Santanu> example, even if I don't unlock the mutex in the thread
    Santanu> above and create my own thread and make it use 'printf',
    Santanu> it succeeds all the time. Could you please clarify?

It is just an example. In fact by default the C library is thread-safe
anyway so the mutex is redundant, but this behaviour is controlled by

    Santanu> Also, there is another less important problem i am
    Santanu> facing. All the sample programs are running fine on both
    Santanu> Fedora and Debian, except that the twothreads program is
    Santanu> not running under Fedora. I get no error, but it does not
    Santanu> print anything either (whereas under Debian it runs just
    Santanu> fine). Can anyone please point me to the right direction
    Santanu> to start looking.

There have been a number of updates to the synthetic target since the
2.0 release, to cope with changes in the toolchain and apparent
problems with the Linux kernel on some processors. You may want to try
the current version from anoncvs, see


Bart Veer                       eCos Configuration Architect
http://www.ecoscentric.com/     The eCos and RedBoot experts

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

More information about the Ecos-discuss mailing list