The convenient C library
you've always been looking for.

Containers, Unicode, regex, HTTP parsing, sockets, time and lock-free concurrency, auto-reclaimed temporary strings and arrays, written in plain C and tested on Linux (glibc and musl), macOS and Windows.

#include <mulle-core/mulle-core.h>   // everything
cc main.c -lmulle-core              // one link

Why mulle-core

libc gives you strings, stdio and not much more. mulle-core covers the things you would otherwise write yourself or collect from a dozen different projects.

Used in production by mulle-objc.

mulle-core is the foundation of mulle-objc, an Objective-C that is statically linkable, unloadable and real-time capable, and runs wherever C does.

What's inside

30 modules from the mulle-c, mulle-concurrent and mulle-core GitHub organizations, combined into one distribution. mulle-core is an amalgamation, so you build and link one library instead of thirty. Each module is also a standalone project, if you only want one of them.

⚡ Lock-free concurrency

mulle-aba

Timestamp-based ABA problem solver

🗄️ Containers & memory

🔤 Text, unicode & parsing

mulle-utf

UTF-8/16/32 analysis & manipulation

mulle-url

URL character validation (scheme, host, path, …)

mulle-http

Streaming HTTP request/response parser

🔢 Formatting, I/O & time

mulle-buffer

Growable char array & stream, stack + heap

🧩 System & networking

mulle-socket

Cross-platform TCP sockets (POSIX + Winsock)

mulle-spawn

Run programs without fork, system or shell

🧱 Foundation

Demos

Seven terminal programs, each built so that a constituent does the heavy lifting instead of making a token appearance. They show, with numbers, what each part of mulle-core is good at. Every demo is self-contained and builds mulle-core from source.

mredis — a Redis-shaped server

Speaks RESP2 over TCP with a small command set (PING, SET, GET, DEL, EXISTS, QUIT). Each connection gets its own thread, and all threads share one lock-free hash table. Redis is single-threaded by design; mredis takes the opposite approach, which mulle-concurrent makes practical, with mulle-socket handling the networking. It reaches 10.2M requests/s with 64 connections and 4.1× the throughput of redis-server at eight threads, because it scales with the number of cores while Redis stays on one.

mulle-concurrent · mulle-thread · mulle-socket · mulle-spawn

See the demos

multigrep

Parallel text search over memory-mapped files: one producer, N workers and a drain loop, with no locks on the hot path.

mulle-mmap · mulle-concurrent · mulle-multififo · mulle-utf

logtop

A live terminal dashboard for a log stream that shows counts, a histogram and throughput.

mulle-concurrent · mulle-multififo · mulle-data

windowrb

Keeps many short-lived ordered sets over a stream, so the cost of creating and tearing down an rbtree shows up in the numbers instead of disappearing as a rounding error.

mulle-rbtree · mulle-storage · mulle-arena

urltoolkit

Validates, cross-checks and rewrites URLs with two independent parsers, and sorts out the cases where they disagree.

mulle-url · mulle-http · mulle-regex · mulle-slug

blackboard

Seven processes publish through one shared 256 KiB region. The mmap holds a heap, locks and FIFOs, and a note can be freed by a different process than the one that allocated it.

mulle-mmapallocator · mulle-mmap · mulle-spawn · mulle-fifo

hashspace

In the concurrent maps the hash is the key, so it matters which hash values are legal. hashspace runs both maps and shows what each one accepts.

mulle-concurrent · mulle-aba

Quick start

Three steps. CMake downloads the mulle-core sources into your build tree for you.

  1. 1Fetch it in CMake

    include( FetchContent)
    
    set( MULLE__CORE_TAG "master" CACHE STRING "branch or tag to fetch mulle-core from")
    FetchContent_Declare( MULLE__CORE
       GIT_REPOSITORY https://github.com/mulle-core/mulle-core.git
       GIT_TAG        "${MULLE__CORE_TAG}")
    FetchContent_MakeAvailable( MULLE__CORE)
    
    add_executable( hello-core src/main.c)
    target_link_libraries( hello-core PRIVATE mulle-core)
  2. 2Write code

    #include <mulle-core/mulle-core.h>
    #include <string.h>
    
    static int   compare_strings( void **a, void **b, void *userinfo)
    {
       MULLE_C_UNUSED( userinfo);
       return( strcmp( (char *) *a, (char *) *b));
    }
    
    int main( void)
    {
       void   *item;
    
       // the array copies each string, and everything is freed when the block exits
       mulle_array_do( array, &mulle_container_keycallback_copied_cstring)
       {
          mulle_array_add( array, "VfL");
          mulle_array_add( array, "Bochum");
    
          mulle_buffer_do( buffer)
          {
             mulle_buffer_sprintf( buffer, "%zu", mulle_array_get_count( array) + 1846);
             mulle_array_add( array, mulle_buffer_get_string( buffer));
          }
    
          mulle_array_qsort_r_inline( array, compare_strings, NULL);
    
          mulle_array_for_reverse( array, item)
          {
             mulle_printf( "%s\n", item);
          }
       }
    
       return( 0);
    }
  3. 3Build and run

    cmake -S . -B build-debug -DCMAKE_BUILD_TYPE=Debug
    cmake --build build-debug --parallel
    ./build-debug/hello-core

The first configure clones mulle-core into build-debug/_deps. To pin a release, pass -DMULLE__CORE_TAG=0.9.0. Develop with Debug and ship with Release: a Debug build keeps assert() active, so mistakes abort right where they happen. If you'd rather keep the sources in your own tree, use a submodule or a plain clone and point add_subdirectory at it. The README lists all installation methods.

Lock-free concurrency example

The resizable hashmap is wait-free: every operation finishes in a bounded number of steps, whatever the other threads are doing. There are no locks, so nothing to spin on and nothing to deadlock.

#include <mulle-core/mulle-core.h>
#include <assert.h>
#include <string.h>

int main( void)
{
   struct mulle_concurrent_hashmap   map;
   char                              *key = "mulle-core";
   void                              *value;
   intptr_t                          hash;

   mulle_aba_init( NULL);               // one-time setup
   mulle_aba_register();                // per thread

   mulle_concurrent_hashmap_init( &map, 0, NULL);

   // wait-free from any thread:
   // the hash is the key, so it must be a legal one: 0 is NO_HASH
   hash  = (intptr_t) mulle_hash( key, strlen( key));
   if( ! hash)
      hash = 1;
   mulle_concurrent_hashmap_register( &map, hash, key);
   value = mulle_concurrent_hashmap_lookup( &map, hash);
   assert( value == key);

   mulle_concurrent_hashmap_done( &map);
   mulle_aba_unregister();
   mulle_aba_done();
   return( 0);
}
  • Wait-free hashmap. Register, insert, lookup and remove are all wait-free.
  • Lock-free linked list & FIFOs. Queues for single and multiple producers and consumers.
  • ABA solved. mulle-aba uses per-thread timestamps to make reuse-after-free detectable, on every supported platform.
  • Resizing without blocking. The map migrates to a larger table atomically while callers keep working.
  • Just C. No runtime and no garbage collector, and it works with any allocator.

CI-tested across platforms

CI builds and tests mulle-core with these compilers:

Ubuntu GCC Clang TinyCC
Windows MSVC Win32 MSVC Win64 GCC
macOS Clang GCC

Built in release (-O3) and debug configurations.