Posted to tcl by apn at Sat Nov 15 06:36:22 GMT 2014view raw

  1. struct MyEvent {
  2. Tcl_Event tcl_ev;
  3. /* Define your own fields below */
  4. int foo;
  5. };
  6.  
  7. In the enqueuing thread
  8.  
  9. struct MyEvent *ev = ckalloc(sizeof(MyEvent));
  10. ev->tcl_ev.proc = my_event_handler; /* This is called from the Tcl event loop */
  11. ev->foo = 42;
  12. Tcl_ThreadQueueEvent(Id of receiving thread, evP, TCL_QUEUE_TAIL);
  13. Tcl_ThreadAlert(Id of receiveing thread); /* Wake up the thread */
  14.  
  15. The receiving thread event handler my_event_handler will be called from
  16. the Tcl event loop

Comments

Posted by apn at Sat Nov 15 06:39:15 GMT 2014 [text] [code]

Forgot to mention, the memory must be ckalloc'ed as Tcl will free it. The my_event_handler routine should return 1 for Tcl to remove the event from the queue else it will stay there.