[En-Nut-Discussion] rs232d: closing socket while other thread is write blocked on socket

Ole Reinhardt ole.reinhardt at embedded-it.de
Sun Nov 29 20:02:48 CET 2009


Hi Henrik,

> It came to my attention that the rs232d.c demo actually closes the socket
> while the other thread could still be write blocked on it. In that scenario
> the socket is destroyed while being used.
>
> For example Receiver() is blocked in the fwrite() call while main()  returns
> from StreamCopy() due to connection break down and calls fclose(). 
> 
> Shouldn't in such a use case fwrite and fclose be synchronised by mutexes?

Indeed, you are right. I would say that a mutex is needed here.
Everywhere where a file descriptor or any other resource is shared by
two or more threads a mutex should be used. 

Bye,

Ole

-- 

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