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

struct MyEvent {
  Tcl_Event tcl_ev;
  /* Define your own fields below */
  int foo;
};

In the enqueuing thread

struct MyEvent *ev = ckalloc(sizeof(MyEvent));
ev->tcl_ev.proc = my_event_handler; /* This is called from the Tcl event loop */
ev->foo = 42;
Tcl_ThreadQueueEvent(Id of receiving thread, evP, TCL_QUEUE_TAIL);
Tcl_ThreadAlert(Id of receiveing thread); /* Wake up the thread */

The receiving thread event handler my_event_handler will be called from
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.