[Openmcl-devel] [openmcl-devel] Enabling interrupts on a thread

Gary Byers gb at clozure.com
Fri Sep 28 02:47:45 UTC 2007

There's an old Woody Allen joke, in which he claims to have failed a
theology test when he was cauught cheating by looking into the soul of
the boy sitting next to him.

Of course, that's the sort of thing that GDB's good at (peering into 
the ... er, um, souls ... of threads, that is.)

A thread has an associated data structure called a "thread context
record" (or "TCR") associated with it.  You can obtain a thread's
TCR in gdb by making it "current" in the GDB sense and calling

(gdb) call get_tcr(0)

That'll return an address of C type "(tcr *)" and set a GDB
"convenience variable" to that address ($n, where n is a small
integer).  If you then do:

(gdb) p/x *$n                   # where n is that small integer

you'll see output that looks like:

(gdb) p/x *$1
$2 = {next = 0x402637e8, prev = 0x402637e8, single_float_convert = {
     tag = 0x1, f = 0x0}, linear = 0x2aaaaaac9458, save_rbp = 0x2aaaaad0cf40,
   lisp_mxcsr = 0x1900, foreign_mxcsr = 0x1f80, db_link = 0x2aaaaad0cf98,
   catch_top = 0x2aaaaad5dd2d, save_vsp = 0x2aaaaad0cee8,
   save_tsp = 0x2aaaaad5dd10, foreign_sp = 0x7fffa34cac60, cs_area = 0x64b970,
   vs_area = 0x6477d0, ts_area = 0x6478b0, cs_limit = 0x7fffa329a000,
   bytes_allocated = 0x0, log2_allocation_quantum = 0x11,
   interrupt_pending = 0x0, xframe = 0x0, errno_loc = 0x2aaaaaac9400,
   ffi_exception = 0x1f80, osid = 0x2aaaaaac95c0, valence = 0x1,
   foreign_exception_status = 0x0, native_thread_info = 0x0,
   native_thread_id = 0xacf, last_allocptr = 0x300040d40000,
   save_allocptr = 0x300040d36870, save_allocbase = 0x300040d1bf30,
   reset_completion = 0x647710, activate = 0x647740, suspend_count = 0x0,
   suspend_context = 0x0, pending_exception_context = 0x0, suspend = 0x6476b0,
   resume = 0x6476e0, flags = 0x0, gc_context = 0x0,
   termination_semaphore = 0x0, unwinding = 0x0, tlb_limit = 0x4000,
   tlb_pointer = 0x647960, shutdown_count = 0x4, next_tsp = 0x2aaaaad5dd10,
   safe_ref_address = 0x0}

though of course the addresses that you see will be different.
The TCR's "thread-local-binding" pointer contains ... thread-local binding

(gdb) x/gx 0x647960
0x647960:	0x0000000000000042
0x647968:	0x0000000000000000
0x647970:	0x0000000000000042

The second of those values - at 0x647968 - is the value of the thread's
binding of CCL:*INTERRUPT-LEVEL*.  That variable's value is -1 when 
interrupts are disabled and 0 when they're enabled; that particular
special variable is a little more special than others, but it's just
a special variable.

If it's -1, that fixnum value would look like 0xfffffffffffffff8 in GDB
on x86-64.

Obviously, changing the value of a special variable this way is grounds
for dismissal from any self-respecting theology class.  (Fortunately,
the thread-specific binding of most other special variables is harder
to find.)

On Thu, 27 Sep 2007, David Rager wrote:

> Hello,
> Sorry, in the interest of brevity, I gave up some relevant detailts.
> I'd like to enable interrupts on a thread that's already waiting on a
> semaphore.  This thread has interrupts disabled, so interupting it
> with a #'break isn't working.  I'm willing to use either LISP or gdb
> to do this.  A guess is that there's a variable or thread register
> that I should set from GDB?  I looked in level-1/l1-lisp-threads.lisp,
> but didn't see the answer.
> Thanks,
> David
> On 9/27/07, Gary Byers <gb at clozure.com> wrote:
>> In 1.1,
>> executes BODY with interrupts enabled.
>> On Thu, 27 Sep 2007, David Rager wrote:
>>> Hello,
>>> I seem to recall there being a way to enable interrupts on a thread
>>> that's otherwise interruptible.  Would someone mind refreshing me with
>>> what that way is?  Of course this only works if the thread that you
>>> enable interrupts on doesn't go and re-disable them, but it might work
>>> for threads waiting on semaphores/locks.
>>> Thanks,
>>> David
>>> _______________________________________________
>>> Openmcl-devel mailing list
>>> Openmcl-devel at clozure.com
>>> http://clozure.com/mailman/listinfo/openmcl-devel

More information about the Openmcl-devel mailing list