i'm building a C socket server, it uses threads, and I want to support multi threading , just like in Java I can use synchronize, I wanna do that too on C socket, but I can't find anything like it, does anyone know anything about that?
Asked
Active
Viewed 162 times
0
-
1What do you mean by "synchronize" a socket? If you just want to have one thread per socket, accept the new socket connection in your "main" thread, create a new thread, and pass the newly accepted socket to the thread and then forget about it in the "main" thread. – Some programmer dude May 17 '19 at 16:02
-
2Java's `synchronized` keyword is directed toward using objects' or classes' *monitor*s to provide mutual exclusion. In this context ["monitor" means about the same thing as "mutex"](https://stackoverflow.com/a/38160073/2402272), and you'll typically see the latter term, not the former, used in conjunction with C. Whatever threading library you happen to be using will surely provide mutexes or an equivalent, whether it is C11 threads, pthreads, or something else. – John Bollinger May 17 '19 at 16:11
-
2You'll also want to look at *condition variables*, which provide the functionality of Java's `Object.wait()`, `Object.notify()`, and `Object.notifyAll()`. Again, different threading implementations will provide their own varieties of these. – John Bollinger May 17 '19 at 16:13