Adding signal handler to a function in C for a thread library -


I am writing a basic User Level Thread Library. Function prototype thr_create (start_func_pointer, arg) for thread creation {make_context (context_1, start_func)}

start_func user will be defined and can change based on user / program

Once the thread is created, if I start to execute it using swapcontext (context_1, context_2)

function start_func starts running Now, if any signal comes, then I have to handle it. Unfortunately, I have handle for start_func, so I can not really define the signal function inside start_func

There is a way I can add a signal handling structure inside start_function The code can indicate something like

thr_create (start_func_pointer, arg) {start_func.add_signal_hanlding_structure = my_signal_handler ();

If you are talking about catching the actual signals running on the actual operating system, I believe that you have to expand this application and then have to put down the signals in each thread (more on later). The problem with this is that if you are trying to use two (or more) alarms of your thread, then it becomes complicated, which is of SIGALRM Uses - When a real signal occurs when you can hold it, but then why do you give it (one or all threads)?

If you are talking about sending and holding a signal between the thread inside a program using your library, then the signal is ready to run as a thread to mark it Will be motivated to, even if it is waiting for something before, and then the functionality to deal with any signal will be asked with your thread resume code if I ask you from your previous questions or Coming so you have thread_yield function called called to run the next thread. If this is the case then the thread_yield was called thread_yield in the current thread before checking a list of pending signals and returning their jobs. Something is different).

As far as registering signal handlers, the main function in POSIX (either directly or indirectly). So you can have:

  Fixed id foo_flag = 0; Static zero foo_handle (int sig) {foo_flag = 1; } Int start_func (zero * arg) {thread_sig_register (SIGFOO, foo_handle); Thread_pause (); // This is a function that you can write that due to the current thread // is not ready to run itself and then call the thread_ld, so that // thread_pause () is something else (hint) Will be returned due to // Ready to run thread again If (foo_flag) {printf ("I found SIGFOO \ n"); } Other {printf ("I do not know what I want to raise"); } Return 0; }  

Now, from another thread, you can send this thread to a SIGFOO (which is just an indication that I created for display purposes).

There will be a way to mark the signal handler table (or list, or some) and pending signal list or pending signal in block (or whatever you are calling them) (Possibly in some priority-based order) and headler action that thread is done for each pending signal before returning to the normal code.


Comments