Project Home
Project Home
Documents
Documents
Wiki
Wiki
Discussion Forums
Discussions
Project Information
Project Info
Forum Topic - thread_pool_destroy hangs with sample code for RM: (3 Items)
   
thread_pool_destroy hangs with sample code for RM  
Using the sample code in the documentation, with slight modifications, thread_pool_destroy hangs.  Specifically, I took 
the sample, and modified thread_pool_create to use 0 (so thread_pool_start would exit).  This allows me to call a 
function like CreateRMProcessor, and later, when shutting down the RM, call DestroyRMProcessor to free all the allocated
 memory, stop the thread pool and destroy it, etc.  Other than that, the code is pretty much along the lines of the 
sample.  The issue is in my DestroyRMProcessor, when I call thread_pool_destroy, it hangs.

I've posted the code here.  Anyone have any ideas whats going on under the covers in the dispatch_* or resmgr_* 
libraries.  I expected the destroy to unblock the threads waiting in dispatch_block, and then for them to exit somehow. 
 But they appear to be stuck in there somewhere.

thanks.

static
RMInfo *
CreateRMProcessor(char *deviceName, uint16_t instance)
{
    RMInfo *rmInfo = NULL;

    rmInfo = malloc(sizeof(RMInfo));
    memset(rmInfo, 0, sizeof(RMInfo));
    // resmgrid returns -1 if failure...so have to initialize here to
    // know in Destroy if it completed or not
    rmInfo->resmgrid = -1;

    /* initialize dispatch interface */
    if((rmInfo->dpp = dispatch_create()) == NULL) {
        fprintf(stderr,
            "Unable to allocate dispatch handle.\n");
        DestroyRMProcessor(rmInfo);
        return NULL;
    }

    fprintf(stderr, "started qnx RM\n");


    rmInfo->pool_attr.handle = rmInfo->dpp;
    rmInfo->pool_attr.context_alloc = dispatch_context_alloc;
    rmInfo->pool_attr.block_func = dispatch_block;
    rmInfo->pool_attr.handler_func = dispatch_handler;
    rmInfo->pool_attr.context_free = dispatch_context_free;

    rmInfo->pool_attr.lo_water = 2;
    // we could have lots of cgwds accessing us...
    rmInfo->pool_attr.hi_water = 256;
    rmInfo->pool_attr.increment = 1;
    rmInfo->pool_attr.maximum = 256;

    if((rmInfo->tpp = thread_pool_create(&rmInfo->pool_attr,
                                /*POOL_FLAG_EXIT_SELF*/0)) == NULL) {
        fprintf(stderr, "Unable to initialize thread pool\n");
        DestroyRMProcessor(rmInfo);
        return NULL;
    }

    /* initialize functions for handling messages */
    iofunc_func_init(_RESMGR_CONNECT_NFUNCS, &rmInfo->connect_funcs,
                                _RESMGR_IO_NFUNCS, &rmInfo->io_funcs);

//  rmInfo->io_funcs.devctl = Ioctl;

    /* initialize attribute structure used by the device */
    iofunc_attr_init(&rmInfo->ioAttr.attr, S_IFNAM | 0666, 0, 0);
    rmInfo->ioAttr.instance = instance;

    /* initialize resource manager attributes */
    rmInfo->resmgr_attr.nparts_max = 1;
    rmInfo->resmgr_attr.msg_max_size = 2048;

    /* attach our device name */
    rmInfo->resmgrid = resmgr_attach(
                        rmInfo->dpp, /* dispatch handle */
                        &rmInfo->resmgr_attr, /* resource manager attrs */
                        deviceName, /* device name */
                        _FTYPE_ANY, /* open type */
                        0, /* flags */
                        &rmInfo->connect_funcs, /* connect routines */
                        &rmInfo->io_funcs, /* I/O routines */
                        &rmInfo->ioAttr); /* handle */

    if(rmInfo->resmgrid == -1) {
        DestroyRMProcessor(rmInfo);
        fprintf(stderr, "Unable to attach name.\n");
        return NULL;
    }

    thread_pool_start(rmInfo->tpp);

    return rmInfo;
}

static
void
DestroyRMProcessor(RMInfo *rmInfo)
{

fprintf(stderr, "in Destroy RM Processor\n");

    if(rmInfo == NULL) {
        fprintf(stderr, "Invalid RMInfo\n");
        return;
    }

fprintf(stderr, "Destroy RM Processor: doing pool destroy\n");

// this never seems to end...
//  if(rmInfo->tpp != NULL)
//     ...
View Full Message
Re: thread_pool_destroy hangs with sample code for RM  
Did not read your code...
What version of QNX are you using? 6.3.0 (maybe 6.3.2 too) has synchronization bugs in thread pool implementation which 
make it often hang on destruction.
Re: thread_pool_destroy hangs with sample code for RM  

Version 6.5.0