ThreadNexus is a small C project exploring sockets, threads, and shared state. It includes a minimal server loop, a player/score database, and utilities for testing concurrency behavior.
For more background on Linux environments and code I/O, see: Linux Operating Systems - rsiddiq.com.
- TCP Server Loop: Start/stop a simple TCP server using
pthreads. Note: by default, the server is started inside the test binary. - Player Database: In-memory player registry with basic CRUD.
- Thread Utilities: Helpers for simulating slow work and exercising race conditions.
- Modular Headers: Clear separation between
server.h,database.h, andthreadnexus.h. - Portable Build: Standard
Makefilefor Linux/macOS/WSL.
Note: The layout below omits transient build artifacts (e.g.,
bin/,build/,dist/) that are ignored in version control.
ThreadNexus/ ├── README.md └── ThreadNexus ├── .gitignore ├── Makefile ├── README.md ├── src │ ├── common.c │ ├── common.h │ ├── database.c │ ├── database.h │ ├── server.c │ ├── server.h │ ├── threadnexus.c │ └── threadnexus.h ├── tests │ ├── unittests_conditions.c │ ├── unittests_locks.c │ └── unittests_server.c ├── unit_tests └── unit_tests.c - GCC or Clang
make(recommended)- POSIX threads (usually available by default on Linux/macOS)
- Unix-like environment (Linux, macOS, WSL)
- Criterion unit test framework (
libcriterion-devon Debian/Ubuntu)
make # build make clean # clean artifactsMake sure you are in the directory that contains the
Makefile(for this zip, that’s typicallyThreadNexus/ThreadNexus).
# 0) (Ubuntu/WSL) Install test dependency sudo apt-get update && sudo apt-get install -y libcriterion-dev # 1) Build make # 2) Run tests (this starts the server internally on the default port 5005) ./unit_tests # 3) (Optional) In another terminal, connect while tests are running nc 127.0.0.1 5005Default Port: The test-run server listens on 5005, as set in
src/server.cwithinsetup().
unit_tests— primary executable built by the Makefile. It launches the server (port 5005) and runs the Criterion tests.- No standalone
threadnexusserver binary is produced by default. If you want one, add a smallserver_main.cand amake runtarget (happy to provide a patch).
server.h/server.c: Socket setup, listen/accept loop, per-connection handler threads.database.h/database.c: Player database abstraction and synchronization primitives around shared data.threadnexus.h/threadnexus.c: Common definitions, constants, and glue across modules.tests/*.c: Criterion-based unit tests; they initialize and exercise the server/database.
- Shared data access should be wrapped in mutex-protected functions.
- Long-running operations (e.g., artificial delays) are isolated to avoid blocking the accept loop.
- Thread lifetimes are joined or detached to avoid leaks; ensure clean shutdown on SIGINT.
- Tests are implemented with Criterion under
tests/and executed by./unit_tests. - For quick manual checks, run
./unit_testsand usenc/telnetto send simple commands to127.0.0.1:5005while tests hold the server open.
- Command protocol for client/server interaction
- Persistent storage of player data
- Graceful shutdown hooks and signal handling
- CI workflow (lint + build + tests)