site_archiver@lists.apple.com Delivered-To: darwin-kernel@lists.apple.com a_request = new WriteBuffReq[sizeof(WriteBuffReq)]; a_request = new WriteBuffReq; In the first iteration of the loop, the line containing: a_request = objDriver->get_request(request_mutex); On 13-Dec-05, at 5:49 AM, Yogesh P wrote: Hi Herb, As per your suggestion I have tried using IOLockSleep() in my driver code to put the current running thread in wait. But when these API gets called my driver crashes. The Code snippet for the same is as follow: void* com_My_driver::handle_request_loop(void *data) { com_My_driver* objDriver; WriteBuffReq* a_request; /* pointer to a request.*/ a_request = new WriteBuffReq[sizeof(WriteBuffReq)]; request_mutex = IOLockAlloc(); /* lock the mutex, to access the requests list exclusively. */ IOLockLock(request_mutex); /* do forever... */ while (1) { if(num_requests > 0) /* a request is pending */ { a_request = objDriver->get_request(request_mutex); // get the write request node from the linklist objDriver->handle_request(a_request, thread_id); // handle the incoming write request delete[] a_request; /* and lock the mutex again. */ IOLockLock(request_mutex); } /* if(a_request) */ } /* if(num_requests > 0) */ else { /* wait for a request to arrive. note the mutex will be */ /* unlocked here, thus allowing other threads access to */ /* requests list. */ IOLog("handle_request_loop():: thread '%d' before IOLockSleep\n", thread_id); IOLockSleep(request_mutex, (void*) thread_id, 0); // Driver Crashing Here /* and after we return from IOLockSleep, the mutex */ /* is locked again */ } /* else */ } /* while */ } Is that I am doing something wrong in using these API's ?? Looking for your valuable suggestions. Thanks & Regards, Yogesh Pahilwan Have you looked at IOLockSleep()? Same header file as IOLockLock(). Depending on what kind of driver you are implementing you may want to search the docs and the list archives (and developer.apple.com) for "primary interrupt" and "secondary interrupt". Cheers, H. Hi Herb, Sorry Herb. Now I am replying to the old thread. After loading the driver, threads get created successfully and each thread goes in a big while loop and the loop goes on infinitely. Thanks in advance, Yogesh Pahilwan You will find the entire document enlightening actually :-) H. Hi Herb, Thanks for your valuable suggestion about the threading and synchronization in Mac OS X. I am also thankful to Garth for his suggestions. Thanks, Yogesh This email sent to bogvardi@gmail.com _______________________________________________ Do not post admin requests to the list. They will be ignored. Darwin-kernel mailing list (Darwin-kernel@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/darwin-kernel/site_archiver%40lists.a... At a glance I see several problems in the code that you posted. The line containing: is allocating an *array* of WriteBuffReq objects (with sizeof (WriteBuffReq) objects in the array, in-fact it's actually allocating sizeof(WriteBuffReq) ^ 2 bytes here), is that really what you want? Wouldn't the following be sufficient Is leaking the large array that you previously allocated, probably not what you intended (if the request is coming from get_request you probably don't need to allocate a WriteBuffReq at all). And, I can't see what - if anything request_mutex is actually protecting. If com_My_driver::handle_request_loop is executed on multiple threads, each thread will have it's own request_mutex object - there will be no synchronization between the threads. If com_My_driver::handle_request_loop is run only on a single thread, request_mutex doesn't seem to have an obvious purpose either. Nobody will ever be able to signal request_mutex because it it a stack variable, the IOLockSleep will sleep forever. As for what is crashing - nothing obvious stood out. But, I don't think it really matters at this point as the algorithm is flawed. The real issue is IOKit probably does everything you are trying to recreate, and quite elegantly too. Your time would be best spent figuring out how to build this part of your driver with the already provided IOKit classes. int thread_id = *((int*) data); /* thread identifying number */ if(a_request) /* got a request - handle it and free it */ { IOLockUnlock(request_mutex); On Fri, 2005-12-09 at 00:04, Herb Petschauer wrote: No worries, the less confusion that my addled brain is exposed to, the better... On 08 Dec 2005 18:31:02 +0530, Yogesh P <pahilwan.yogesh@spsoftindia.com> wrote: I am actually implementing a threading and synchronization mechanism for accessing a request queue which is a queue of write data structure having singly linklist. I am creating kernel threads in my init() driver function. These threads access the request queue paralelly by using IOKit's IOLock synchronization primitives. Each thread acquire the lock calling IOLockLock() function and check the request queue whether it is empty or not. If the request queue is empty then the thread release the lock by calling IOLockUnLock() function. So that other threads can access the request queue. Now I have to put each thread on a conditional wait. The conditional wait means that if there is no request in the request queue the thread delays for a nanosecond and release the lock from the request queue for that specified time delay, and as soon as the request comes in the request queue, thread wake ups, acquire the lock and process that specified request. Is there any mechanism in IOKit so that I can put the thread on conditional wait ?? After that condition met, wake up that thread to process the specified request ?? On Wed, 2005-12-07 at 22:01, Herb Petschauer wrote: Again, this email seems to be a new thread. Why not just reply to the old thread? Anway: http://developer.apple.com/documentation/Darwin/ Conceptual/KernelProgramming/services/chapter_16_section_2.html On 07 Dec 2005 18:22:18 +0530, Yogesh P <pahilwan.yogesh@spsoftindia.com> wrote: Now my driver is not getting crash when I call the IOCreateThread() function. Is there any API to put the kernel thread in a wait for a nanosecond in sleep in IOKit?? _______________________________________________ Do not post admin requests to the list. They will be ignored. Darwin-kernel mailing list (Darwin-kernel@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/darwin-kernel/bogvardi% 40gmail.com _______________________________________________ Do not post admin requests to the list. They will be ignored. Darwin-kernel mailing list (Darwin-kernel@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/darwin-kernel/cliff_russell% 40atimi.com This email sent to cliff_russell@atimi.com This email sent to site_archiver@lists.apple.com