A new version of the Advanced Resource Embedder is now available. The tool allows to embed files in binaries by producing C, Ada or Go source files that contain the file to embed.
Tag - C
Advanced Resource Embedder 1.2.0
By Stephane Carrez2022-01-23 09:04:00
Advanced Resource Embedder 1.1.0
By Stephane Carrez2021-07-04 16:52:00
Release 1.1.0 of the Advanced Resource Embedder is available with new formats to represent files in the generated Ada and C sources.
Advanced Resource Embedder for Ada, C and Go
By Stephane Carrez2021-06-11 12:43:00
Incorporating files in a binary program can sometimes be a challenge. The Advance Resource Embedder is a flexible tool that collects files such as documentation, images, scripts, configuration files and generates a source code that contains these files.
Fixing the mysql_thread_end cleanup bug in libmysql
By Stephane Carrez2012-09-08 09:39:10
If you see the following message when an application stops, the fix is for you.
Error in my_thread_global_end(): 5 threads didn't exit
The message comes from the MySQL C connector when the library cleans up before the program exits.
The MySQL C client connector has a bug that exists for many years in multi-threaded applications: it does not cleanup correctly threads that use the library. Interestingly, MySQL documentation says you must call mysql_thread_end yourself before a thread stops. This is a shame as it forces developers to find impossible and dirty workaround, one of them is nicely explained in Bug 846602 - MySQL C API missing THR_KEY_mysys.
Root cause
The origin of the bug comes from a wrong use or a miss-understanding of the POSIX Threads. Indeed, the library uses the thread-specific data management through pthread_getspecific and pthread_setspecific to store some dynamically allocated object associated with each thread. The POSIX 1003.1c standard has defined a cleanup mechanism that can be used to automatically reclaim storage that was allocated for thread specific data.
The pthread_key_create is the operation called to create a new thread specific data key. When the key is created, it allows to register a cleanup handler that will be called with the thread specific data before the thread exits. A cleanup handler is as simple as the following function:
static void thread_cleanup(void* data)
{
free(data);
}
With such cleanup handler, the pthread data key must be created as follows:
static pthread_key_t THR_KEY_mysys;
...
pthread_key_create(&THR_KEY_mysys, thread_cleanup);
The MySQL C connector does not specify any cleanup handler when creating the pthread data key. The patch attached to this post defines the cleanup handler and installs it as described above.
Fixing MySQL C connector
To fix the MySQL connector, you will need the sources, apply the patch and build the sources. Download the Connector/C sources from MySQL site. The patch is against 6.0.2 but you should be able to apply it to other versions easily (it patches the file mysys/my_thr_init.c
that was not changed since 2009). Extract the sources and apply the patch:
tar xzf mysql-connector-c-6.0.2.tar.gz
patch < fix-mysql-connector.diff
To build the connector, you will need CMake. The build process is explained in the sources (read BUILD.unix
).
cmake -G "Unix Makefiles"
make
make install
Beware that before building you may have to change some configuration setup according to your system (check include/mysql_version.h
).
Patch
Tags
- Facelet
- NetBSD
- framework
- Mysql
- generator
- files
- application
- gcc
- ReadyNAS
- Security
- binutils
- ELF
- JSF
- Java
- bacula
- Tutorial
- Apache
- COFF
- collaboration
- planning
- project
- upgrade
- AWA
- C
- EL
- J2EE
- UML
- php
- symfony
- Ethernet
- Ada
- FreeBSD
- Go
- KVM
- MDE
- Proxy
- STM32
- Servlet
- backup
- lvm
- multiprocessing
- web
- Bean
- Jenkins
- release
- OAuth
- ProjectBar
- REST
- Rewrite
- Sqlite
- Storage
- USB
- Ubuntu
- bison
- cache
- crash
- Linux
- firefox
- performance
- interview