Comments (3)
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.
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.
thanks.
It would be nice to add this code directly to log.c
from log.c.
Related Issues (20)
- Is thread safe ? HOT 3
- Log level enumaration
- Will it be slow if heavy request, too many IO process. Why not split the thread for logging? HOT 1
- Why skipped fflush(L.fp) in function log_log()? HOT 1
- Convert internal lock-management to pthread HOT 1
- Logs to syslog()
- NULL safety
- Lock before changing level
- using log_set_level(int level). HOT 1
- More Explanation/ Documentation HOT 3
- Copyright year
- How to redirect messages to text file? HOT 1
- Why keep multiple callbacks HOT 2
- how can I print thread ID HOT 1
- Maximum log file size reached HOT 1
- How tf do i set a callback funtion?? HOT 1
- Is this library multiprocess safe? HOT 2
- How to using a file to record GLOBAL LOG messages
- How to limit the log file size?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from log.c.