Handling ionotify() for multithreaded client process

Hi Folks,

I am writing a resource manager which implement read/write/poll functions. and I am encountering a lock up problem when a client thread uses “poll” function to poll POLLIN event on the file descriptor while another client thread is doing the read/write operation to the same file descriptor. The client thread calling “poll” function keeps waiting for the event to be delivered until time out occurs, while the read/write operation finishes with success. The problem happens not very often.

In my resource manager, I am using “iofunc_notify” and “iofunc_notify_trigger” to implement “poll” io_function. While reading the manual(qnx.com/developers/docs/mome … G_ionotify), I found there is a caveat reads:
[color=red]Currently, the API for notification handling from your resource manager doesn’t support multithreaded client processes very well. Problems may arise when a thread in a client process requests notification and other threads in the same client process are also dealing with the resource manager. This is not a problem when the threads are from different processes.”

It seems that some synchronize protection has to be added in. But should the protection in client side or the resource manager side or both? Is there any tricky thing to implement ionotify() method in a resource manager for multithreaded client process? It’s not clear from the manual.

The code I am using is very similar with the manual:
//resource manager handle function for poll
io_notify(resmgr_context_t *ctp, io_notify_t *msg, RESMGR_OCB_T *ocb)
my_file_t *file = (my_file_t *) ocb->private;
int trig;

trig = _NOTIFY_COND_OUTPUT;         /* clients can always give us data */
if (!list_empty(file->list))
    trig |= _NOTIFY_COND_INPUT;      /* we have some data available */

 * iofunc_notify() will do any necessary handling, including adding
 * the client to the notification list is need be.

return (iofunc_notify(ctp, msg, file->notify, trig, NULL, NULL));


//when there’s data coming, this is called
if (IOFUNC_NOTIFY_INPUT_CHECK(file->notify, 1, 0))
iofunc_notify_trigger(file->notify, 1, IOFUNC_NOTIFY_INPUT);