Comments (6)
On top use that instead of forcing the _POSIX_C_SOURCE define :
# if defined(__APPLE__)
# include <AvailabilityMacros.h>
# else
# ifndef _POSIX_C_SOURCE
# define _POSIX_C_SOURCE 200809L
# endif
# endif
c99-pedantic.patch
(Tested : compile without any warnings or errors (BTW you can't dereference func_ptr to void* : nada verboten): on Debian 7, iOS (min-version 6.0) and MacOS (min-version 10.7), Android (min-version lollipop) gcc, gcc-clang and clang toolchains)
--- thpool_original.c 2018-03-21 13:46:04.000000000 -0700
+++ thpool_pedantic.c 2018-03-21 13:45:05.000000000 -0700
@@ -8,7 +8,17 @@
*
********************************/
-#define _POSIX_C_SOURCE 200809L
+
+# if defined(__APPLE__)
+# include <AvailabilityMacros.h>
+# else
+# ifndef _POSIX_C_SOURCE
+# define _POSIX_C_SOURCE 200809L
+# elif _POSIX_C_SOURCE < 200809L
+# error "Valid _POSIX_C_SOURCE version required."
+# endif
+# endif
+
#include <unistd.h>
#include <signal.h>
#include <stdio.h>
@@ -94,7 +104,7 @@
static int thread_init(thpool_* thpool_p, struct thread** thread_p, int id);
-static void* thread_do(struct thread* thread_p);
+static void* thread_do(void * arg);
static void thread_hold(int sig_id);
static void thread_destroy(struct thread* thread_p);
@@ -123,8 +133,8 @@
threads_on_hold = 0;
threads_keepalive = 1;
- if (num_threads < 0){
- num_threads = 0;
+ if (num_threads < 1){
+ num_threads = 1;
}
/* Make new thread pool */
@@ -290,7 +300,7 @@
(*thread_p)->thpool_p = thpool_p;
(*thread_p)->id = id;
- pthread_create(&(*thread_p)->pthread, NULL, (void *)thread_do, (*thread_p));
+ pthread_create(&(*thread_p)->pthread, NULL, thread_do, (*thread_p));
pthread_detach((*thread_p)->pthread);
return 0;
}
@@ -314,8 +324,13 @@
* @param thread thread that will run this function
* @return nothing
*/
-static void* thread_do(struct thread* thread_p){
+static void* thread_do(void * arg){
+ struct thread * thread_p = (struct thread *)arg;
+ if (thread_p == NULL){
+ err("thread_do(): Could not access cookie\n");
+ return NULL;
+ }
/* Set thread name for profiling and debuging */
char thread_name[128] = {0};
sprintf(thread_name, "thread-pool-%d", thread_p->id);
from c-thread-pool.
FWIW, this is what's on my system. All the _np
decls are guarded by this. It seems you might have luck with _DARWIN_C_SOURCE
.
#if (!defined(_POSIX_C_SOURCE) && !defined(_XOPEN_SOURCE)) || defined(_DARWIN_C_SOURCE)
/* returns non-zero if pthread_create or cthread_fork have been called */
__OSX_AVAILABLE_STARTING(__MAC_10_4, __IPHONE_2_0)
int pthread_is_threaded_np(void);
from c-thread-pool.
I can't really recall exactly the reasoning behind it (my commit should probably be more informative).
However my gut feeling is that the macro is overriding existing information in your case. Do you think you can try the below on a Mac and see if it solves it?
#if ! defined(_POSIX_C_SOURCE)
#define _POSIX_C_SOURCE 200809L
#endif
from c-thread-pool.
@Pithikos nope, same results.
cc: @mnunberg
from c-thread-pool.
the way these macros normally work is that they make your compiler run in a specific 'mode'. According to the POSIX standard (http://pubs.opengroup.org/onlinepubs/007904975/functions/xsh_chap02_02.html):
Additional symbols not required or explicitly permitted by IEEE Std 1003.1-2001 to be in that header shall not be made visible, except when enabled by another feature test macro.
It might be the case that you need to include an os-x specific header (maybe *mach*
.h) to get the _np functionality.
from c-thread-pool.
Hi ! I'm having the same warning
from c-thread-pool.
Related Issues (20)
- If a child thread holding a mutex is terminated by "thpool_destroy(thpool)", what will happen to the mutex?
- example.c: fix a warning HOT 1
- Support for a priority queue for the jobqueue.
- support to zephyr RTOS HOT 1
- Can I pass multiple parameters to the thpool_add_work() method? HOT 2
- Why is `threads_keepalive` a global variable? HOT 1
- why do you define bsem *has_jobs; ? HOT 1
- When a thread is in an endless loop, can it not exit and be destroyed? HOT 1
- unexcpected output HOT 1
- Reinitialization of mutex and cond in bsem_reset is a bug
- Why don't threadpool lock num_threads_working? HOT 1
- Does not improve runtime while using this threadpool implementation
- Is it possible to wait for a specific task?
- Doesn't release memory until job queue is empty? HOT 1
- thpool.c has leftovers after some merge HOT 1
- question about threads_keepalive variable. HOT 1
- 'SIGUSR1' undeclared HOT 1
- Errors when compiling with C++
- Any question weclomed in https://github.com/52coder/C-Thread-Pool
- The execution result seems to be something wrong while I use the Thread pool? HOT 1
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 c-thread-pool.