websockets and mutli-threading

165 views
Skip to first unread message

Jonathan Berling

unread,
Sep 24, 2013, 12:46:14 PM9/24/13
to mongoos...@googlegroups.com
I noticed that mg_websocket_write contains a comment that it's not thread safe. (Line 4195). What does this mean exactly? Does this mean that multiple threads cannot write to the same connection at the same time? Or does it mean that only one thread can write at any time, even if they are to different connections?

Thanks,
Jonathan

Sergey Lyubka

unread,
Sep 24, 2013, 1:03:53 PM9/24/13
to mongoose-users
On Tue, Sep 24, 2013 at 5:46 PM, Jonathan Berling <jonbe...@gmail.com> wrote:
I noticed that mg_websocket_write contains a comment that it's not thread safe. (Line 4195). What does this mean exactly? Does this mean that multiple threads cannot write to the same connection at the same time? Or does it mean that only one thread can write at any time, even if they are to different connections?

For any given connection, only one thread should be writing to it.
Are you looking for broadcasting to all websocket connections?

 

Thanks,
Jonathan

--
You received this message because you are subscribed to the Google Groups "mongoose-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongoose-user...@googlegroups.com.
To post to this group, send email to mongoos...@googlegroups.com.
Visit this group at http://groups.google.com/group/mongoose-users.
For more options, visit https://groups.google.com/groups/opt_out.

Sergey Lyubka

unread,
Sep 24, 2013, 1:05:31 PM9/24/13
to mongoose-users
On Tue, Sep 24, 2013 at 6:03 PM, Sergey Lyubka <val...@gmail.com> wrote:



On Tue, Sep 24, 2013 at 5:46 PM, Jonathan Berling <jonbe...@gmail.com> wrote:
I noticed that mg_websocket_write contains a comment that it's not thread safe. (Line 4195). What does this mean exactly? Does this mean that multiple threads cannot write to the same connection at the same time? Or does it mean that only one thread can write at any time, even if they are to different connections?

For any given connection, only one thread should be writing to it.

That statement is ambiguous :-)  This is better: For any given connection, only one thread should be writing to it at any given time. That means, many threads could write into a given connection provided that writes are serialized by e.g. mutex lock.

Jonathan Berling

unread,
Sep 24, 2013, 1:59:57 PM9/24/13
to mongoos...@googlegroups.com
Thanks Sergey. That's what I wanted to know. I will have multiple
connections/threads, but no two threads will be writing to the same
connection at the same time. It sounds like my use case is supported.
> You received this message because you are subscribed to a topic in the
> Google Groups "mongoose-users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/mongoose-users/6khOpJQeqSI/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to

Sergey Lyubka

unread,
Sep 24, 2013, 2:20:21 PM9/24/13
to mongoose-users
On Tue, Sep 24, 2013 at 6:59 PM, Jonathan Berling <jonbe...@gmail.com> wrote:
Thanks Sergey. That's what I wanted to know. I will have multiple
connections/threads, but no two threads will be writing to the same
connection at the same time. It sounds like my use case is supported.

Yes, your case is supported.
I was suggested to make mg_write and mg_read() thread-safe, I think this is a good thing to do.
Reply all
Reply to author
Forward
0 new messages