byannoni / qthreads Goto Github PK
View Code? Open in Web Editor NEWA POSIX thread wrapper using a pool and queues of functions for C and (soon) C++
License: Apache License 2.0
A POSIX thread wrapper using a pool and queues of functions for C and (soon) C++
License: Apache License 2.0
The name threading_queue is misleading. Perhaps thread_pool would be better.
qtpool
)qt
)There is no reason why fq_push() should take a struct rather than creating a struct out of two arguments internally. It's a pain to set up a struct for each element by hand. New signature could be:
enum pt_error fq_push(struct function_queue*, void (*)(void*), void*, int);
There is a lack of error handling and reporting in these function. The functions should return consistent error codes. This could be implemented through an enum, however that may not be as effective for tq_start()
One possible solution is to modify tq_start() to take a pointer parameter for storing the number of successful thread creations. This would free the return value for the enum.
This is what you need -> http://www.wtfpl.net/
There is no reason why a thread should wait a certain amount of time if nothing else is running.
Flags may be valuable in some use cases when creating the threads.
In function_queue.c, attr is never destroyed. Possible fixes:
The logic that checks if malloc()
succeeds in fq_init()
is the opposite. It should be changed from:
ret = PT_EMALLOC
pml = pthread_mutex_destroy(&q->lock)
if(pml == 0) {
to
ret = PT_EMALLOC
pml = pthread_mutex_destroy(&q->lock)
} else {
if(pml == 0) {
Additionally, PT_EPTMUNLOCK
is the wrong error code, it should be PT_EPTMINIT
.
Use a condition variable to block to elimination repeated unnecessary checking in get_and_run(). Call pthread_cond_signal() from fq_push() and pthread_cond_wait() from fq_pop().
Perhaps a more efficient locking system can be used, or threads can be notified individually or a semaphore could be used to implement ticket locking?
It's a pain to manage a hand written makefile for every change. Perhaps autotools or CMake should be used.
As it currently is, the function queue cannot resize with realloc()
because the elements pointer could be dereferenced while it points to freed memory (before the pointer has been replaced with the new memory). A work-around could be to allocated with malloc()
and manually copy the data from the original queue over, all while holding the lock.
Some files contain Windows line endings when read on Linux systems
Allow tq_start() to report all errors, and optionally stop and reverse creation on error.
Possibly add a function specifically for checking errors from init_attr_ret
Valgrind indicates that the cleanup handler introduced by 9272e01 attempts to unlock an unlocked mutex. This results in undefined behavior according to the POSIX standard.
The call is probably not necessary. Read about preemptive multithreading.
The pointer q
is dereferenced before it is checked. The simple fix is to initialize tmp
to 0 instead of using the value of q
immediately
The error handling is a mess. The functions should return consistent error codes. This will be implemented through an enum. The enum value indicating the error status will be the return value the functions.
If pthread_cancel()
fails then pthread_join()
may block forever.
The destructors for threading_queue and function_queue both throw exceptions.
This should not happen. Possibly fix it with pthread_cleanup_push().
Refactor C++ constructors not to call fq_init() or tq_init(). Create new methods for that purpose.
The name is misleading. Perhaps tp::pool would be better.
Ideally this will happen after #27 for easier integration.
The function fq_peek() can block when calling fq_is_empty() even if the block parameter is 0. The block parameter should be passed on to it instead of the constant 1.
It should read "while destroying," not "while unlocking"
The function fq_pop() can block when calling fq_is_empty() even if the block parameter is 0. The block parameter should be passed on to it instead of the constant 1.
The function fq_push() can block when calling fq_is_full() even if the block parameter is 0. The block parameter should be passed on to it instead of the constant 1.
Currently, the CI script specifically installs gcc-4.8. This may no longer be necessary. Determine if this can be removed.
It should look much cleaner and be less flaggy
fqinit()
fqdestroy()
fqpush()
fqpop()
fqpeek()
qtstrerror_r()
qtinit()
qstart_get_e()
-- restructure returns; no goto
The makefile should be changed to allow for other compilers.
The pointer src
is dereferenced before it is checked. Initialize len
to 0 and then assign the calculated length after checking.
Adding a debug target to the makefile could be useful for building and testing
Some of the badges in README.md link to pages that don't exist
Automated tests should be created to ensure quality
This will facilitate the implementation of #16.
The solution must:
This would allow the mutex to be non-recursive and make fq_is_empty() and fq_is_full() simpler.
As it is currently, the function_queue queue requires contiguous memory, which may not be available. If the memory is not required to be contiguous then there is a smaller chance of a failure to allocate.
tq_stop() should optionally join with each canceled thread
The function get_and_run()
is of type void* (*) (struct function_queue*)
but is called as void* (*)(void*)
. This results in undefined behavior according to the C Standard:
If a converted pointer is used to call a function whose type is not compatible with the pointed-to type, the behavior is undefined.
tq_start_get_ne()
is not thread-safe and it is not very useful either. It should be removed.
Hey Brandon,
I just wanted to drop by and ask some existential questions.
Why does this project exist? What is the purpose of this? What problem does this solve?
Thanks,
Alex
This will use the GitHub wiki for this project for now
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.