mardi 5 juin 2018

Threads overriding other threads errno

I don't have this problem yet because I havn't written the code yet. But I may run over this problem at some point.

Assume I have a multi threaded application. One thread reads from a hardware interface (CAN in my case) and puts the read messages into a (capable) queue. The other thread takes the messages and sends them via TCP to a server. Basic CAN logging application.

Now both threads use write and read calls to do the respective operations. But any of these could fail setting errno appropriately.

So theoretically it is possible for one thread to call write, then fail, then get suspended, and then the other thread fails with another call to and resets the errno before the first thread could read it.

How can I fix/mitigate this problem?

Aucun commentaire:

Enregistrer un commentaire