Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing header #1

Open
jonface opened this issue Oct 31, 2013 · 3 comments
Open

Missing header #1

jonface opened this issue Oct 31, 2013 · 3 comments

Comments

@jonface
Copy link

jonface commented Oct 31, 2013

I was required to add unistd.h to threadpool_test.cpp, not sure if it was just me.

Thanks.

Ubuntu 12.10
gcc (Ubuntu/Linaro 4.7.2-2ubuntu1) 4.7.2

@bilash
Copy link
Owner

bilash commented Oct 31, 2013

I think you are right. Maybe when I tested this I had sleep() commented out.

Thanks for pointing it out!

@nalisaki
Copy link

nalisaki commented Oct 5, 2014

Hi, is there a way to start a thread (already finished) second time without calling pthread_create? Or can the finished thread be restarted? Thanks very much!

oh, I find a way:(I am sorry I have no idea about how to format c++ source code)
void* ThreadProcWrapper(void * pParam)
{
Thread* threadPtr = (Thread_) pParam;
while(1)
{
if(threadPtr->m_finished)
{
sleep(1);
continue;
}
threadPtr->m_proc(threadPtr->m_params);
threadPtr->m_finished = true;
}
}
user can access via an Thread interface:
typedef void_ (ThreadProcPtr)(void * pParam);
void Thread::start(const ThreadProcPtr proc , void
param);

@celliott181
Copy link
Contributor

@nalisaki this would be better discussed in a different forum, however a threadpool is designed for exactly the sort of work you're asking about. The pool itself is a set of threads available to handle any processing given to the threadpool. You should not be directly accessing threads, instead going through the threadpool object. This object will take care of handing off work to individual threads, and storing returned data in an easily accessible way.
You can see this in action in the threadpool_test.cpp code, where a set of four tasks is handed to a threadpool with 2 threads available. The threads process all four tasks without requiring a new thread to be created for each task.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants