Hi,
I'm learning to use Boost.asio by going through the tutorials at [1].
However, the listing for "Synchronizing handlers in multithreaded programs" crashes on my Ubuntu. Source listing (about 70 lines) is at [2]. I have given my compilation steps, stack trace from gdb, and boost information below. Can you please advise how I can get this working right?
[1] https://www.boost.org/doc/libs/1_77_0/doc/html/boost_asio/tutorial.html
[2] https://www.boost.org/doc/libs/1_77_0/doc/html/boost_asio/tutorial/tuttimer5...
I compiled and ran as follows:
$ g++ -g -o timer_5.1 timer_5.1.cpp -lpthread -lboost_thread
$ ./timer_5.1
Timer 1: 0
Timer 2: 1
Timer 1: 2
Timer 2: 3
Timer 1: 4
Timer 2: 5
Timer 1: 6
Timer 2: 7
Timer 1: 8
Timer 2: 9
Segmentation fault (core dumped)
The backtrace from gdb is:
$ cat gdb_log.txt
#0 0x00007ffff799f88b in ?? () from /usr/lib/x86_64-linux-gnu/libboost_thread.so.1.65.1
#1 0x00007ffff79a0bd5 in ?? () from /usr/lib/x86_64-linux-gnu/libboost_thread.so.1.65.1
#2 0x00007ffff7bbb6db in start_thread (arg=0x7ffff6851700) at pthread_create.c:463
#3 0x00007ffff711e71f in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95
I have the following boost library installed:
$ sudo apt show libboost-all-dev
Package: libboost-all-dev
Version: 1.65.1.0ubuntu1
Priority: optional
Section: universe/libdevel
Source: boost-defaults
Origin: Ubuntu
Maintainer: Ubuntu Developers