mosquitto_lib_init thread-safe or only to be called once per process?

Asked by Tommy Svensson

Hi,

I got a segmentation fault in mosquitto_lib_init when it was called simultaneously from two different threads. Guarding mosquitto_lib_init with a mutex made the fault go away.

Now I wonder, is the mosquitto_lib_init to be called only once for each process? Or is to be called once for each thread, in which case it must be thread-safe, which it looks like it isn't. The docs says that mosquitto is thread-safe though.

Can you please clarify!

Kind regards,
/Tommy

Env: mosquitto v1.2.3 on Ubuntu 13.04

Question information

Language:
English Edit question
Status:
Answered
For:
mosquitto Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Roger Light (roger.light) said :
#1

Hi Tommy,

You are correct, this does need clarifying! In fact mosquitto_lib_init
is not thread safe. I have updated the documentation to say this.

Thanks,

Roger

On Tue, Dec 17, 2013 at 12:51 PM, Tommy Svensson
<email address hidden> wrote:
> New question #240923 on mosquitto:
> https://answers.launchpad.net/mosquitto/+question/240923
>
> Hi,
>
> I got a segmentation fault in mosquitto_lib_init when it was called simultaneously from two different threads. Guarding mosquitto_lib_init with a mutex made the fault go away.
>
> Now I wonder, is the mosquitto_lib_init to be called only once for each process? Or is to be called once for each thread, in which case it must be thread-safe, which it looks like it isn't. The docs says that mosquitto is thread-safe though.
>
> Can you please clarify!
>
> Kind regards,
> /Tommy
>
> Env: mosquitto v1.2.3 on Ubuntu 13.04
>
>
> --
> You received this question notification because you are a member of
> Mosquitto PPA, which is an answer contact for mosquitto.

Revision history for this message
Christian S. Perone (christian-perone) said :
#2

So, now it is clear to me that the init isn't thread safe, but should I call it once per process or once on each thread using locking ?

Revision history for this message
Roger Light (roger.light) said :
#3

Just once should be fine.

Can you help with this problem?

Provide an answer of your own, or ask Tommy Svensson for more information if necessary.

To post a message you must log in.