# Cross-thread violation

**URL:** <https://www.ruby-forum.com/t/cross-thread-violation/69466>\
**Category:** Ruby\
**Created:** [February 17, 2006, 12:20am UTC](https://www.ruby-forum.com/t/cross-thread-violation/69466 "2006-02-17T00:20:40Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![rakaur](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/bcef8e/32.png) [@rakaur](https://www.ruby-forum.com/u/rakaur)\
**Post date:** [February 17, 2006, 12:20am UTC](https://www.ruby-forum.com/t/cross-thread-violation/69466/1 "2006-02-17T00:20:40Z")

</div>

/usr/local/lib/ruby/1.8/monitor.rb:218: [BUG] cross-thread violation on  
rb\_thread\_schedule()  
ruby 1.8.4 (2005-12-24) [i386-freebsd4]

Abort trap (core dumped)

$ gdb `which ruby` ruby.core  
GNU gdb 4.18 (FreeBSD)  
Copyright 1998 Free Software Foundation, Inc.  
GDB is free software, covered by the GNU General Public License, and  
you are  
welcome to change it and/or distribute copies of it under certain  
conditions.  
Type “show copying” to see the conditions.  
There is absolutely no warranty for GDB. Type “show warranty” for  
details.  
This GDB was configured as “i386-unknown-freebsd”…(no debugging  
symbols found)…  
Core was generated by `ruby’.  
Program terminated with signal 6, Abort trap.  
Reading symbols from /usr/local/lib/libruby18.so.18…(no debugging  
symbols found)…done.  
Reading symbols from /usr/lib/libcrypt.so.2…(no debugging symbols  
found)…done.  
Reading symbols from /usr/lib/libm.so.2…(no debugging symbols  
found)…done.  
Reading symbols from /usr/lib/libc\_r.so.4…(no debugging symbols  
found)…done.  
Reading symbols from  
/usr/local/lib/ruby/site\_ruby/1.8/i386-freebsd4/idn.so…  
(no debugging symbols found)…done.  
Reading symbols from /usr/local/lib/libidn.so.16…(no debugging  
symbols found)…done.  
Reading symbols from /usr/local/lib/libgnugetopt.so.1…(no debugging  
symbols found)…done.  
Reading symbols from /usr/local/lib/libiconv.so.3…(no debugging  
symbols found)…done.  
Reading symbols from  
/usr/local/lib/ruby/1.8/i386-freebsd4/stringio.so…(no debugging  
symbols found)…  
done.  
Reading symbols from  
/usr/local/lib/ruby/1.8/i386-freebsd4/syck.so…(no debugging symbols  
found)…done.  
Reading symbols from  
/usr/local/lib/ruby/1.8/i386-freebsd4/socket.so…(no debugging symbols  
found)…done.  
Reading symbols from  
/usr/local/lib/ruby/1.8/i386-freebsd4/digest/md5.so…(no debugging  
symbols found)…  
done.  
Reading symbols from /usr/local/lib/libcrypto.so.4…(no debugging  
symbols found)…done.  
Reading symbols from  
/usr/local/lib/ruby/1.8/i386-freebsd4/digest.so…(no debugging symbols  
found)…done.  
Reading symbols from  
/usr/local/lib/ruby/1.8/i386-freebsd4/fcntl.so…(no debugging symbols  
found)…done.  
Reading symbols from  
/usr/local/lib/ruby/1.8/i386-freebsd4/openssl.so…(no debugging  
symbols found)…done.  
Reading symbols from /usr/local/lib/libssl.so.4…(no debugging symbols  
found)…done.  
Reading symbols from /usr/local/lib/ruby/1.8/i386-freebsd4/nkf.so…(no  
debugging symbols found)…done.  
Reading symbols from /usr/libexec/ld-elf.so.1…(no debugging symbols  
found)…done.  
#0 0x2819b584 in kill () from /usr/lib/libc\_r.so.4  
(gdb) bt  
#0 0x2819b584 in kill () from /usr/lib/libc\_r.so.4  
#1 0x281e9b9e in abort () from /usr/lib/libc\_r.so.4  
#2 0x2808333d in rb\_bug () from /usr/local/lib/libruby18.so.18  
#3 0x280990c6 in rb\_thread\_schedule () from  
/usr/local/lib/libruby18.so.18  
#4 0x2809a678 in rb\_thread\_pass () from /usr/local/lib/libruby18.so.18  
#5 0x280908c1 in rb\_call0 () from /usr/local/lib/libruby18.so.18  
#6 0x280913d0 in rb\_call () from /usr/local/lib/libruby18.so.18  
#7 0x2808b5ff in rb\_eval () from /usr/local/lib/libruby18.so.18  
#8 0x28090f40 in rb\_call0 () from /usr/local/lib/libruby18.so.18  
#9 0x280913d0 in rb\_call () from /usr/local/lib/libruby18.so.18  
#10 0x2808b8a4 in rb\_eval () from /usr/local/lib/libruby18.so.18  
#11 0x2808ae10 in rb\_eval () from /usr/local/lib/libruby18.so.18  
#12 0x28090f40 in rb\_call0 () from /usr/local/lib/libruby18.so.18  
#13 0x280913d0 in rb\_call () from /usr/local/lib/libruby18.so.18  
#14 0x2808b5ff in rb\_eval () from /usr/local/lib/libruby18.so.18  
#15 0x2808a732 in rb\_eval () from /usr/local/lib/libruby18.so.18  
#16 0x28090f40 in rb\_call0 () from /usr/local/lib/libruby18.so.18  
#17 0x280913d0 in rb\_call () from /usr/local/lib/libruby18.so.18  
#18 0x2808b5ff in rb\_eval () from /usr/local/lib/libruby18.so.18  
#19 0x28090f40 in rb\_call0 () from /usr/local/lib/libruby18.so.18  
#20 0x280913d0 in rb\_call () from /usr/local/lib/libruby18.so.18  
#21 0x2808b82c in rb\_eval () from /usr/local/lib/libruby18.so.18  
#22 0x280964e9 in block\_pass () from /usr/local/lib/libruby18.so.18  
#23 0x2808a560 in rb\_eval () from /usr/local/lib/libruby18.so.18  
#24 0x28090f40 in rb\_call0 () from /usr/local/lib/libruby18.so.18  
#25 0x280913d0 in rb\_call () from /usr/local/lib/libruby18.so.18  
#26 0x2808b5ff in rb\_eval () from /usr/local/lib/libruby18.so.18  
#27 0x28090f40 in rb\_call0 () from /usr/local/lib/libruby18.so.18  
#28 0x280913d0 in rb\_call () from /usr/local/lib/libruby18.so.18  
#29 0x2808b5ff in rb\_eval () from /usr/local/lib/libruby18.so.18  
#30 0x28090f40 in rb\_call0 () from /usr/local/lib/libruby18.so.18  
#31 0x280913d0 in rb\_call () from /usr/local/lib/libruby18.so.18  
#32 0x2808b8a4 in rb\_eval () from /usr/local/lib/libruby18.so.18  
#33 0x2808ea1f in rb\_yield\_0 () from /usr/local/lib/libruby18.so.18  
#34 0x28095e7c in proc\_invoke () from /usr/local/lib/libruby18.so.18  
#35 0x28096002 in proc\_call () from /usr/local/lib/libruby18.so.18  
#36 0x28090892 in rb\_call0 () from /usr/local/lib/libruby18.so.18  
#37 0x280913d0 in rb\_call () from /usr/local/lib/libruby18.so.18  
#38 0x28091801 in rb\_funcall2 () from /usr/local/lib/libruby18.so.18  
#39 0x28087b11 in rb\_eval\_cmd () from /usr/local/lib/libruby18.so.18  
#40 0x28097ed2 in run\_trap\_eval () from /usr/local/lib/libruby18.so.18  
#41 0x2808fb1a in rb\_protect () from /usr/local/lib/libruby18.so.18  
#42 0x280980a5 in rb\_trap\_eval () from /usr/local/lib/libruby18.so.18  
#43 0x2809b7ad in rb\_thread\_trap\_eval () from  
/usr/local/lib/libruby18.so.18  
#44 0x280eab45 in signal\_exec () from /usr/local/lib/libruby18.so.18  
#45 0x280eab92 in sighandler () from /usr/local/lib/libruby18.so.18  
#46 0x281ad723 in \_thread\_sig\_handler () from /usr/lib/libc\_r.so.4  
#47 0x281ae9bc in \_thread\_sig\_wrapper () from /usr/lib/libc\_r.so.4  
#48 0x0 in ?? ()  
(gdb)

Seems like a stack overflow, but I can’t seem to figure what’s doing it.

---

<div class="post-metadata">

**Author:** ![rakaur](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/bcef8e/32.png) [@rakaur](https://www.ruby-forum.com/u/rakaur)\
**Post date:** [February 17, 2006, 1:15am UTC](https://www.ruby-forum.com/t/cross-thread-violation/69466/2 "2006-02-17T01:15:24Z")

</div>

On Friday 17 February 2006 08:18 am, rakaur wrote:

Heh, well okay. I received the exact same error on NetBSD 2.0.2  
yesterday  
afternoon when I was working on a project. I still have the core and  
tells  
similar information. Though, I’m using Ruby 1.8.3, I’m surprised the bug  
hasn’t been ran in to before, especially since portupgrade in FreeBSD  
ports  
is completely ruby based.

Tsume

---

<div class="post-metadata">

**Author:** ![rakaur](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/bcef8e/32.png) [@rakaur](https://www.ruby-forum.com/u/rakaur)\
**Post date:** [February 17, 2006, 1:45am UTC](https://www.ruby-forum.com/t/cross-thread-violation/69466/3 "2006-02-17T01:45:38Z")

</div>

Apparently this was caused when I did something along the lines of.

Thread.new do  
Timeout.new…  
…  
end

Timeout.new was a typo, should have been Timeout::timeout. I don’t know  
why this  
completely killed the interpreter though.

---

<div class="post-metadata">

**Author:** ![rakaur](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/bcef8e/32.png) [@rakaur](https://www.ruby-forum.com/u/rakaur)\
**Post date:** [February 17, 2006, 3:55am UTC](https://www.ruby-forum.com/t/cross-thread-violation/69466/4 "2006-02-17T03:55:17Z")

</div>

Hi,

In message “Re: cross-thread violation”  
on Fri, 17 Feb 2006 09:43:28 +0900, “rakaur” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
writes:

|Apparently this was caused when I did something along the lines of.  
|  
|Thread.new do  
| Timeout.new…  
| …  
|end  
|  
|Timeout.new was a typo, should have been Timeout::timeout. I don’t know  
|why this  
|completely killed the interpreter though.

It is possible to show us a script to reproduce your problem?

```
						matz.

```

---

<div class="post-metadata">

**Author:** ![rakaur](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/bcef8e/32.png) [@rakaur](https://www.ruby-forum.com/u/rakaur)\
**Post date:** [February 17, 2006, 9:10am UTC](https://www.ruby-forum.com/t/cross-thread-violation/69466/5 "2006-02-17T09:10:41Z")

</div>

Sorry, I should clarify “kills it.” It doesn’t actually kill the  
interpreter until I issue SIGINT, or ^C. When it gets the iterrupt, it  
dumps core with “abort trap.”

---

<div class="post-metadata">

**Author:** ![rakaur](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/bcef8e/32.png) [@rakaur](https://www.ruby-forum.com/u/rakaur)\
**Post date:** [February 17, 2006, 9:04am UTC](https://www.ruby-forum.com/t/cross-thread-violation/69466/6 "2006-02-17T09:04:39Z")

</div>

require ‘timeout’

Thread.new do  
begin  
Timeout.new(10) do  
sleep(11)  
end  
rescue Timeout::Error  
puts “trying again”  
retry  
end  
end

loop { sleep(1) }

This kills it on FreeBSD 4.11, but not on Linux 2.6.13. Note that  
“Timeout.new” is invalid, but that’s how I got it to do it in the first  
place.

I was trying to make use of Timeouts to do a hacky timer system (eg, a  
block that’s run every N seconds). I figured by doing:

Thread.new do  
begin  
Timeout::timeout(N) { sleep(N + 1) }  
rescue Timeout::Error  
# some code to run every N seconds  
retry  
end  
end

I could accomplish that. By making the mistake Timeout.new instead of  
Timeout::timeout is how I originally caused this to happen. After  
changing it to Timeout::timeout it does work as I intended.
