[En-Nut-Discussion] Calling the same function from different threads.

Ole Reinhardt ole.reinhardt at embedded-it.de
Wed Dec 2 11:52:37 CET 2009


> However, because they are allways listening, both threads calls the getc
> functions and I think it can be a problem.  On the one hand, I can test the
> UART tasks and it works fine, but when I open the TCP port the systems
> doesn't work further, neither UART and TCP.  TCP thread is based in the
> tcps.c sample.

Take a look into rs232d.c which might be what you are planning to do.

There should be no problem if you call the file io functions from
different threads. There are only very few functions that are not
thread safe at all (and those should be marked in the documentation).

If you use the same file descriptor from different threads, use a mutex
to lock concurrent access. Otherwise you might get interleaved data if
you call e.g. fprintf on the same filedscriptor from both threads.

If your program hangs you might have produced a buffer overflow. Or do
you have an endless loop without thread switching point?

If this does not help, please post your code here, so we could help you


Ole Reinhardt


Thermotemp GmbH, Embedded-IT

Embedded Hard-/ Software and Open Source Development, 
Integration and Consulting

Geschäftsstelle Siegen - Steinstraße 67 - D-57072 Siegen - 
tel +49 (0)271 5513597, +49 (0)271-73681 - fax +49 (0)271 736 97

Hauptsitz - Hademarscher Weg 7 - 13503 Berlin
Tel +49 (0)30 4315205 - Fax +49 (0)30 43665002
Geschäftsführer: Jörg Friedrichs, Ole Reinhardt
Handelsregister Berlin Charlottenburg HRB 45978 UstID DE 156329280 

More information about the En-Nut-Discussion mailing list