A new event handling architecture
Posted: Sun Jul 06, 2008 12:08 pm
Okay, heres one really whacky ipc/event handling idea that i had. It is only suitable for kernel threads. It might involve some amount of overhead if this gets to the user mode. But as far as my os is concerned, i don't currently have any user mode and hence i found the implementation really nice and not slow as such.
Lets take a simple thread which is declared in the following fashion:
Now in this function the 'signal' parameter which is passed by the scheduler to the thread upon creation is the new addition. This is where the thread receives the signal/event from other threads. Now it is possible for the thread to receive a signal on creation as well as at runtime.
The runtime part is the new idea. When a thread signals this test_thread, the scheduler simply adds one more thread to the system with the same entry point ('test_thread') passing the signal to it. This happens asynchronously even when the actual test_thread is running. The only difference as far as kernel threads are concerned is the stack that the new thread uses which is different from the thread that the actual test_thread is using. So to handle the signal we just have to write the following code:
Here the thread doesnt have to wait for events and get blocked. The new thread automatically handles the signal as and when required.
So how do you find this architecture?
Lets take a simple thread which is declared in the following fashion:
Code: Select all
int test_thread(void *args,unsigned long signal)
{
//do work
}
The runtime part is the new idea. When a thread signals this test_thread, the scheduler simply adds one more thread to the system with the same entry point ('test_thread') passing the signal to it. This happens asynchronously even when the actual test_thread is running. The only difference as far as kernel threads are concerned is the stack that the new thread uses which is different from the thread that the actual test_thread is using. So to handle the signal we just have to write the following code:
Code: Select all
int test_thread(void *args,unsigned long signal)
{
if(signal) {
//handle the signal
return 0;
}
//do work
}
So how do you find this architecture?