Re: (e)poll takeover

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> Hi
>
> I have tried to find a way to have a thread take over the event waiting from
> another thread. This should be done without context switching.
>
> A more precise description:
>
> 1. Thread A are waiting in poll or epoll.
> 2. Thread B decides to take over the waiting. This means stopping thread A
> from responding to new events and go into a (e)poll for the same events.
> 3. After handling some events thread B decides to let thread A take over
> again.

the most obvious thing, though probably not what you want...

thread B:

pthread_kill(threadA, SIGSTOP);
// handle events
pthread_kill(threadA, SIGCONT);

other than that, put a loopback "control" pipe in the interest set, wake
up thread A via a write to the pipe, let it block and wake it up later by
whatever mechanism you like (conditionals,...) once thread B is finished
handling events

you could try doing more elaborate things with pthread_kill, custom signal
handlers and sigsetjmp to get thread A out of the polling loop, but I
don't think any of this will be more efficient than a control pipe

as for avoiding a context switch on 3... just postpone waking up the
thread as soon as you can tolerate a context switch (is this some
real-time thing?)

however all that still begs the question why you don't just let the
threads swap roles

Best regards
-- 
Helge Bahmann <hcb@xxxxxxxxxxxxxxx>                     /| \__
The past: Smart users in front of dumb terminals       /_|____\
                                                     _/\ |   __)
Wer im finally-Block sitzt, sollte nicht             \\ \|__/__|
mit exceptions werfen.                                \\/___/ |
                                                        |


-
: send the line "unsubscribe linux-net" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux 802.1Q VLAN]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Git]     [Bugtraq]     [Yosemite News and Information]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux PCI]     [Linux Admin]     [Samba]

  Powered by Linux