set_buffer_internal_2 (current_buffer);
}
- if (!NILP (current_thread->error_symbol))
+ /* We could have been signaled while waiting to grab the global lock
+ for the first time since this thread was created, in which case
+ we didn't yet have the opportunity to set up the handlers. Delay
+ raising the signal in that case (it will be actually raised when
+ the thread comes here after acquiring the lock the next time). */
+ if (!NILP (current_thread->error_symbol) && handlerlist)
{
Lisp_Object sym = current_thread->error_symbol;
Lisp_Object data = current_thread->error_data;
acquire_global_lock (self);
- { /* Put a dummy catcher at top-level so that handlerlist is never NULL.
- This is important since handlerlist->nextfree holds the freelist
- which would otherwise leak every time we unwind back to top-level. */
- handlerlist_sentinel = xzalloc (sizeof (struct handler));
- handlerlist = handlerlist_sentinel->nextfree = handlerlist_sentinel;
- struct handler *c = push_handler (Qunbound, CATCHER);
- eassert (c == handlerlist_sentinel);
- handlerlist_sentinel->nextfree = NULL;
- handlerlist_sentinel->next = NULL;
- }
+ /* Put a dummy catcher at top-level so that handlerlist is never NULL.
+ This is important since handlerlist->nextfree holds the freelist
+ which would otherwise leak every time we unwind back to top-level. */
+ handlerlist_sentinel = xzalloc (sizeof (struct handler));
+ handlerlist = handlerlist_sentinel->nextfree = handlerlist_sentinel;
+ struct handler *c = push_handler (Qunbound, CATCHER);
+ eassert (c == handlerlist_sentinel);
+ handlerlist_sentinel->nextfree = NULL;
+ handlerlist_sentinel->next = NULL;
/* It might be nice to do something with errors here. */
internal_condition_case (invoke_thread_function, Qt, do_nothing);
(sit-for 1)
(should (= (point) 21))))
+(ert-deftest thread-signal-early ()
+ "Test signaling a thread as soon as it is started by the OS."
+ (let ((thread
+ (make-thread #'(lambda ()
+ (while t (thread-yield))))))
+ (thread-signal thread 'error nil)
+ (sit-for 1)
+ (should-not (thread-alive-p thread))))
+
;;; threads.el ends here