Skip to main content
4 votes
Accepted

pattern to unlock thread and get variable in fast unlock

The basic problem here seems to be that this thread keeps the mutex locked by default, and only unlocks it for a limited period of time when it's sure it doesn't need to the mutex. Normally, you want ...
Jerry Coffin's user avatar
  • 44.9k
4 votes

pattern to unlock thread and get variable in fast unlock

In this function, you lock mutex and keep it locked except for a tiny part, where you do_something, letting the other threads aquire the mutex, before waiting to re-lock it. What's wrong ? When ...
Christophe's user avatar
  • 82.3k
3 votes

C Thread Architecture

From a purely conceptual standpoint, main() is no different than any other thread in the same process. It just happens to be the one that was started first but still shares code and data with every ...
Blrfl's user avatar
  • 20.5k
2 votes

Where to initialize clients in C server?

Whenever one has a requirement which does not fit into the existing module structure of a system, I would recommend to start with a new module first. Said that, during the evolution of this new module,...
Doc Brown's user avatar
  • 221k
2 votes

Should I introduce a controller layer to separate networking from game/player logic in a C server project?

The closest I ever got to C is writing some procedural C++ in college, and I don't build games, so my answer isn't going to provide the exact structure; instead it will describe the approach I would ...
Greg Burghardt's user avatar
2 votes
Accepted

How to handle errors of pthreads fundamental lock und unlock functions?

Nobody handles this error conditions. That they return errors is a typical DesignByComitee problem. The only way to handle them is to crash your process and move error handling to a whole other level. ...
Lothar's user avatar
  • 702
1 vote

Where to initialize clients in C server?

The logic that you describe looks very much like session management, the glue that ties together network connection with a user. As it is a different concern than the ones handled in other modules, ...
Christophe's user avatar
  • 82.3k
1 vote

How to handle errors of pthreads fundamental lock und unlock functions?

Read the pthread documentation and see what errors each function can return. Hopefully there is also a hint there what the best way is to handle such an error. Depending on the kind of error, that ...
Bart van Ingen Schenau's user avatar
1 vote

How should functions that keep state across multiple invocations be made safe?

In the example in case 2, according to the solution in the quote, should the "rand()" function be changed to "unsigned rand(unsigned next_seed)"? /* rand - return pseudorandom ...
Bart van Ingen Schenau's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible