title: using kqueue for EVFILT_USER
body: <p>I have trouble to understand, how to use kqueue for user space events.<br>
  I look for 2 use cases.<br>
  Use case 1: Manual Reset event<br>
  Use case 2: Auto Reset event<br></p>
  
  <p>I think I understand, how to use kqueue() and kevent(), yet I am unclear on how the events passed to kevent() look for the related operations: <br>
  Let there be a struct kevent variable named "event".<br>
  Let us assume, we have no problem finding a new event id which is not colliding with other event ids for that kqueue instance, named "eventId".</p>
  
  <ol>
  <li>Create user event: EV_SET(&amp;event, eventId, EVFILT_USER, EV_ADD, NOTE_FFNOP, 0, NULL) </li>
  <li>Destroy user event: EV_SET(&amp;event, eventId, EVFILT_USER, EV_DESTROY, NOTE_FFNOP, 0, NULL)</li>
  <li>Set the user event: EV_SET(&amp;event, eventId, EVFILT_USER, ?????, NOTE_FFNOP, 0, NULL)</li>
  <li>Reset user event: EV_SET(&amp;event, eventId, EVFILT_USER, ??EV_CLEAR???, 
  NOTE_FFNOP, 0, NULL )</li>
  <li>Pulse user event: EV_SET(&amp;event, eventId, EVFILT_USER, 0, NOTE_TRIGGER, 0, NULL )</li>
  <li>In the wait loop, I think the snipped would be along: if( event.filter == EVFILT_USER &amp;&amp; event.ident == eventId ) { // this is my event! Do something! }</li>
  </ol>
  
  <p>See the ???? in the above EV_SET() calls to see where I need help.<br>
  For use case 1 (Manual reset event), operation (1) Create might look different compared to use case 2 (auto reset event).<br>
  Operations (3) and (4) I am completely in the dark. Might I need EV_ENABLE/EV_DISABLE for those? Where is EV_CLEAR fitting in?<br>
  So far I assume that I do not need to do anything in operation (6) beyond the "dispatching".
  I am pretty positive, that operation (5) could work as I gave it above.</p>
  
  <p>I spent now the better of a day trying to find documentation or samples showing how it is done. I found in apple codebase a kqueue test program but I doubt, it is doing it right. Also, it only sends 1 event in the test and that event terminates the loop of the receiving thread. So it is not helping me to understand the details for my 2 use cases.</p>
  
  <p>I plan to use it under FreeBsd 9.1 on a x86 machine...for now.</p>