Giter Site home page Giter Site logo

Comments (3)

chuckwolber avatar chuckwolber commented on July 29, 2024 4

Possibly, but locking is an extraordinarily complicated topic, and there is no one-size-fits all approach that would work with a portable library like this. For example, the above example only works in POSIX style operating systems, like Linux, BSD, and macOS, that support NPTL.

from log.c.

chuckwolber avatar chuckwolber commented on July 29, 2024 1

If you use proper locking, then yes it would be. Here is an example.

#include <pthread.h>
#include "log.h"

pthread_mutex_t MUTEX_LOG;
void log_lock(bool lock, void *udata);

int main() {
  pthread_mutex_init(&MUTEX_LOG, NULL);
  log_set_lock(log_lock, &MUTEX_LOG);

  /* Insert threaded application code here... */

  pthread_mutex_destroy(&MUTEX_LOG);

  return 0;
}

void log_lock(bool lock, void* udata) {
  pthread_mutex_t *LOCK = (pthread_mutex_t*)(udata);
  if (lock)
    pthread_mutex_lock(LOCK);
  else
    pthread_mutex_unlock(LOCK);
}

from log.c.

skyformat99 avatar skyformat99 commented on July 29, 2024

thanks.
It would be nice to add this code directly to log.c

from log.c.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.