New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable coap_async_trigger() to be called from a different thread #800
Comments
libcoap currently has no multi-thread support / protection, but is on a TODO List. No planned dates. coap_async_trigger() does (multi-thread unsafe) update the coap_context_t structure and does not itself call the request_handler() but relies on (in the epoll enabled case) a timerfd triggering to set the read available on the coap_fd (determined by coap_context_get_coap_fd)). When the data is updated by the worker thread, that too will need to be multi-thread access safe. So currently, this design would not safely work and an alternative needs to be found. |
Well, it's a nice to have feature request. I am totally aware that this is nothing for the near future. Here some personal notes on this topic. Maybe it gives some interesting input for future features. Or you consider it to completely miss the point - which is fine for me either. I see no need for libcoap to be completely thread safe. There might be some performance considerations, but for me it is absolutely reasonable to have the coap context assigned to a single thread. It is a very good design choice. Having said that, there are a few functions I would like to be able to invoke from a different thread. The coap_async_trigger() is one of them. I could consider some kind of event handling, which allows me to queue in events. In the most generic case libcoap could provide an API which allows to queue in a function and its parameter, which is then executed in the context of the coap thread. |
libcoap (if compiled appropriately) is now multi-thread safe in the develop branch |
Related: Issue #794, PR #795
It would be great if coap_async_trigger() could be called from a thread different to that one running the libcoap server code.
Use case: Separate response, where it takes some time to prepare the data for the response.
The text was updated successfully, but these errors were encountered: