Skip to content

pinwhell/spnlck

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SPNLCK – Portable Spinlock for C

A lightweight, cross-platform spinlock implementation for multithreading in C.


Features

  • Works on x86, x64, ARM, ARM64

  • Supports MSVC and GCC/Clang

  • Uses CPU-friendly pause/yield to reduce busy-wait overhead

  • Simple API: init, try_acquire, acquire, release


Quick Start

#include <spnlck/spnlck.h>
#include <stdio.h>

int main() {
    spnlck lock;
    spnlck_init(&lock);

    spnlck_acquire(&lock);
    printf("Critical section!\n");
    spnlck_release(&lock);

    return 0;
}

API

spnlck_init(l) Initialize the spinlock spnlck_try_acquire(l) Try to acquire without blocking spnlck_acquire(l) Acquire and block until available spnlck_release(l) release the lock


License

MIT

About

A lightweight, portable spinlock for C.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published