Open ghost opened 3 years ago
libcoap is not currently multi-threaded safe, so you can only have one thread managing all access to a coap context (coap_context_t) and all the structures that hang off that (e.g. coap_session_t).
That said, there is nothing wrong with thread A managing context A, Thread B managing a completely different context B and so-on.
There is nothing stopping you doing all the libcoap processing in one thread and pass the requests / responses in a thread safe manner across to other threads.
Can I implement (POSIX)multithreading for sending one command in multiple server?
At present, access to/usage of the same coap_context_t*
structures is not thread safe, along with access to/usage of any structures hanging off coap_context_t
, some major examples being `coap_session_tand
coap_resource_t*`.
Providing that there is multi-thread protection access to anything to any functions prefixed by coap_
, then you would be fine.
Alternatively, having 2 different coap_context_t*
is fine providing only one thread access the firstcoap_context_t*
and another thread accesses the second coap_context_t*
.
There has been some work done on trying to make libcoap multi-thread safe, but it is not that straight forward and has not been completed.
libcoap (if compiled appropriately) is now multi-thread safe when using the develop branch.
I want to implement a multi-threaded server which is capable of handling CoAP request/response. Is there any guide available on how to achieve the same?