Commit Graph

16 Commits

Author SHA1 Message Date
Francesco Mazzoli
1cf299bfac Use atomics where appropriate 2024-03-20 13:21:18 +00:00
Francesco Mazzoli
f85714dbba Use pthread_self() to get pthread thread id 2024-03-20 13:11:14 +00:00
Francesco Mazzoli
3a6e498664 Make some Loop methods static 2024-03-20 13:00:18 +00:00
Francesco Mazzoli
66fe0a2621 Correct pthread_timedjoin_np handling 2024-03-20 11:13:26 +00:00
Francesco Mazzoli
8f1ba6361b Resist interruptions when joining threads 2024-03-20 10:32:42 +00:00
Francesco Mazzoli
66ccba6124 Forward termination signal to main thread 2024-03-20 10:32:42 +00:00
Miroslav Crnic
712ed8973e core: simplify implementing custom stop for Loop 2024-02-23 13:52:34 +00:00
Miroslav Crnic
2ec1304981 core: ppoll, futex dont like negative timeouts 2024-01-29 17:00:14 +00:00
Francesco Mazzoli
0a6a0c8f24 Process CDC timeouts in a timely manner 2024-01-29 15:08:06 +00:00
Francesco Mazzoli
d569bdb494 Re-introduce thread names (they got lost in a refactor) 2024-01-11 17:32:52 +00:00
Francesco Mazzoli
c27ba8398a Tear down all threads at once
I had copied the LIFO pattern from ETD codebase, but it's not needed
here given that the loop terminates gracefully and so we can coordinate
explicitly if needed.
2024-01-09 16:53:23 +00:00
Francesco Mazzoli
3097752a30 Minor tweak 2024-01-08 16:03:07 +00:00
Francesco Mazzoli
ee9e0ad0af Remove pthread_attr_setsigmask_np, musl does not have it 2024-01-08 15:58:31 +00:00
Francesco Mazzoli
8075e99bb6 Graceful shard teardown
See <https://mazzo.li/posts/stopping-linux-threads.html> for tradeoffs
regarding how to terminate threads gracefully.

The goal of this work was for valgrind to work correctly, which in turn
was to investigate #141. It looks like I have succeeded:

    ==2715080== Warning: unimplemented fcntl command: 1036
    ==2715080== 20,052 bytes in 5,013 blocks are definitely lost in loss record 133 of 135
    ==2715080==    at 0x483F013: operator new(unsigned long) (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
    ==2715080==    by 0x3B708E: allocate (new_allocator.h:121)
    ==2715080==    by 0x3B708E: allocate (allocator.h:173)
    ==2715080==    by 0x3B708E: allocate (alloc_traits.h:460)
    ==2715080==    by 0x3B708E: _M_allocate (stl_vector.h:346)
    ==2715080==    by 0x3B708E: std::vector<Crc, std::allocator<Crc> >::_M_default_append(unsigned long) (vector.tcc:635)
    ==2715080==    by 0x42BF1C: resize (stl_vector.h:940)
    ==2715080==    by 0x42BF1C: ShardDBImpl::_fileSpans(rocksdb::ReadOptions&, FileSpansReq const&, FileSpansResp&) (shard/ShardDB.cpp:921)
    ==2715080==    by 0x420867: ShardDBImpl::read(ShardReqContainer const&, ShardRespContainer&) (shard/ShardDB.cpp:1034)
    ==2715080==    by 0x3CB3EE: ShardServer::_handleRequest(int, sockaddr_in*, char*, unsigned long) (shard/Shard.cpp:347)
    ==2715080==    by 0x3C8A39: ShardServer::step() (shard/Shard.cpp:405)
    ==2715080==    by 0x40B1E8: run (core/Loop.cpp:67)
    ==2715080==    by 0x40B1E8: startLoop(void*) (core/Loop.cpp:37)
    ==2715080==    by 0x4BEA258: start_thread (in /usr/lib/libpthread-2.33.so)
    ==2715080==    by 0x4D005E2: clone (in /usr/lib/libc-2.33.so)
    ==2715080==
    ==2715080==
    ==2715080== Exit program on first error (--exit-on-first-error=yes)
2024-01-08 15:41:22 +00:00
Francesco Mazzoli
38f3d54ecd Wait forever, rather than having timeouts
The goal here is to not have constant wakeups due to timeout. Do
not attempt to clean things up nicely before termination -- just
terminate instead. We can setup a proper termination system in
the future, I first want to see if this makes a difference.

Also, change xmon to use pipes for communication, so that it can
wait without timers as well.

Also, `write` directly for logging, so that we know the logs will
make it to the file after the logging call returns (since we now
do not have the chance to flush them afterwards).
2023-12-07 10:11:19 +00:00
Francesco Mazzoli
1922cf3c30 Factor out common looping patterns 2023-08-08 09:21:35 +01:00