[asterisk-dev] Newbie question about ast_pthread_create_background
Russell Bryant
russell at digium.com
Thu Sep 10 10:20:03 CDT 2009
Alex Massover wrote:
> The problem is that pargs structure in the thread "destroyed" (contains garbage) from the moment that app_exec() exits and it exits just after creating detached thread. If I put sleep() before exiting from app_exec() everying OK, but the whole idea is to be not blocking. I probaly missing something very basic here.
> Please point me to how I can pass the structure to the detached thread and "keep it there" and been able to exit from app_exec().
The problem is that your arguments to the thread are on the stack. You
need to allocate memory on the heap with ast_malloc(), ast_calloc(), etc.
Also, you probably don't want to use create_background(). You likely
want one of the detached thread variants.
--
Russell Bryant
Digium, Inc. | Engineering Manager, Open Source Software
445 Jan Davis Drive NW - Huntsville, AL 35806 - USA
Check us out at: www.digium.com & www.asterisk.org
More information about the asterisk-dev
mailing list