Next: , Previous: Mutexes and Condition Variables, Up: Scheduling


5.17.6 Blocking in Guile Mode

A thread must not block outside of a libguile function while it is in guile mode. The following functions can be used to temporily leave guile mode or to perform some common blocking operations in a supported way.

— C Function: void * scm_without_guile (void *(*func) (void *), void *data)

Leave guile mode, call func on data, enter guile mode and return the result of calling func.

While a thread has left guile mode, it must not call any libguile functions except scm_with_guile or scm_without_guile and must not use any libguile macros. Also, local variables of type SCM that are allocated while not in guile mode are not protected from the garbage collector.

When used from non-guile mode, calling scm_without_guile is still allowed: it simply calls func. In that way, you can leave guile mode without having to know whether the current thread is in guile mode or not.

— C Function: int scm_pthread_mutex_lock (pthread_mutex_t *mutex)

Like pthread_mutex_lock, but leaves guile mode while waiting for the mutex.

— C Function: int scm_pthread_cond_wait (pthread_cond_t *cond, pthread_mutex_t *mutex)
— C Function: int scm_pthread_cond_timedwait (pthread_cond_t *cond, pthread_mutex_t *mutex, struct timespec *abstime)

Like pthread_cond_wait and pthread_cond_timedwait, but leaves guile mode while waiting for the condition variable.

— C Function: int scm_std_select (int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout)

Like select but leaves guile mode while waiting. Also, the delivery of a system async causes this function to be interrupted with error code EINTR.

— C Function: unsigned int scm_std_sleep (unsigned int seconds)

Like sleep, but leaves guile mode while sleeping. Also, the delivery of a system async causes this function to be interrupted.

— C Function: unsigned long scm_std_usleep (unsigned long usecs)

Like usleep, but leaves guile mode while sleeping. Also, the delivery of a system async causes this function to be interrupted.