Threading and Synchronization in Mass storage Driver
Threading and Synchronization in Mass storage Driver
- Subject: Threading and Synchronization in Mass storage Driver
- From: Yogesh P <email@hidden>
- Date: 09 Nov 2005 20:20:11 +0530
Hi Darwin-kernel Folks,
I am implementing threading and synchronization mechanism in my Mass
storage driver.I had used kernel IOCreateThread() function to create
thread in my driver by passing thread function called
handle_request_loop().I am calling this thread function in my driver's
init() call so that whenever driver gets loaded it should create the
specificied number of threads.
But I am getting the driver crash after loading my driver.
The code snippet for the same is as follows:
bool com_My_driver::init(OSDictionary* properties = 0)
{
int i; /* loop counter */
int thr_id[NUM_HANDLER_THREADS]; /* thread IDs */
/* create the request-handling threads */
for(i = 0; i < NUM_HANDLER_THREADS; i++)// NUM_HANDLER_THREADS=3
{
thr_id[i] = i;
IOThread thread_t =
IOCreateThread((IOThreadFunc)&com_My_driver::handle_request_loop,
(void*) &thr_id[i]);// crashing here
if(thread_t)
{
IOLog("\nInit():: Thread created successfully\n");
}
else
{
I OLog("\nInit():: Thread created unsuccessfully\n");
}
}
return True;
}
void* com_My_driver::handle_request_loop(void *data)
{
WriteBuffReq* a_request; /* pointer to a request.*/
int thread_id = *((int*) data); /* thread identifying number */
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 = get_request(request_mutex);
if(a_request) /* got a request - handle it and free it */
{
IOLockUnlock(request_mutex);
handle_request(a_request, thread_id);
/* and lock the mutex again. */
IOLockLock(request_mutex);
} /* if(a_request) */
} /* if(num_requests > 0) */
else
{
mutex_pause();
} /* else */
} /* while */
}
Is there I am doing something wrong in using threading and
synchronization mechanism in kernel level driver???
Please help me to understand the threading and synchronization mechanism
at kernel level.
Thanks in advance,
Yogesh Pahilwan
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-kernel mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden