8000 Refactor/use worker threads in timer dispatch by saminiir · Pull Request #10 · saminiir/level-ip · GitHub
[go: up one dir, main page]

Skip to content

Refactor/use worker threads in timer dispatch - #10

Merged
saminiir merged 11 commits into
develfrom
refactor/use-worker-threads-in-timer-dispatch
Aug 24, 2017
Merged

saminiir merged 11 commits into
develfrom
refactor/use-worker-threads-in-timer-dispatch

Conversation

@saminiir
Copy link
Copy Markdown
Owner

Introduces stability improvements and removes coding errors related to multithreading:

  • Locking of a socket and its operations is now coarse-grained: Acquire the socket lock on every operation. This makes the multithreading much simpler and most of the race conditions revealed by ThreadSanitizer were removed.
  • Timer thread now dispatches worker threads. This simplifies the locking scheme because the timer thread previously easily deadlocked on a socket's operation.
  • Timer tick resolution is now 10 ms, since with usleep(1000) most of the time was spent just iterating over the timers.

Most of the mutexes are now unused, and should be removed in the near future. Maybe in this changeset even.

saminiir added 11 commits August 6, 2017 14:00
Timer engine now spawns worker threads to run the actual tasks.

Sockets are now strictly locked with sock->lock, since this
simplifies the interplay between timers, input handler and
the user socket handler.
Oops, this caused doublelocking (timer_free) and timers
were never released.
Not sure if this helps that much, but if clearly a thread
only needs to read data from the socket, it can use `rdlock` then.
Lvl-ip spends its most time here, and felt like the 1ms resolution
is a bit too fine for the purposes.
We really want to lock it and not bail out.

Also, added error printing if the lock can't be acquired.
This still isn't how I'd like it to be, but the twist is that
we need to lock the timer, remove it from the list, and only
then can we unlock it. Which begs the question, if refcnt is 0,
nobody should be able to acquire the timer reference anymore!
I know, sleeping like this is not that maintainable. Proper solution
would be to poll the HTTP server for when it's up.
@saminiir
saminiir merged commit bb65e28 into devel Aug 24, 2017
@saminiir
saminiir deleted the refactor/use-worker-threads-in-timer-dispatch branch August 24, 2017 12:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

0