From: Hongli Lai Date: 2008-03-04T19:20:11+09:00 Subject: Re: embedding Ruby 1.9.0 inside pthread Suraj N. Kurapati wrote: > I moved the ruby initialization calls to the main thread as you > suggested and the example worked! The revised main.c is now: You also seem to be using locks in a wrong way. In main() you have: > pthread_mutex_init(&gCProgLock, NULL); > pthread_mutex_lock(&gCProgLock); > > pthread_create(&gRubyThread, NULL, gRubyThread_body, NULL); > pthread_mutex_lock(&gCProgLock); // C program blocks here And in the thread you have: > pthread_mutex_unlock(&gCProgLock); You are unlocking a mutex, which was locked by another thread. This is a violation of the POSIX API. I quote the man page: "!pthread_mutex_unlock! unlocks the given mutex. The mutex is assumed to be locked and owned by the calling thread on entrance to !pthread_mutex_unlock!." If you want to wake up the main thread (which was sleeping on some kind of condition) then you should use conditioned variables instead.