lisp/c/mthread_posix.c
int 
//thd_suspend (pthread_t target_thread)
pthread_suspend (pthread_t target_thread)
{
    int status;
    int i = 0;

    /*
     * The first call to thd_suspend will initialize the
     * package.
     */
    status = pthread_once (&susp_once, suspend_init_routine);
    if (status != 0)
        return status;

    /* 
     * Serialize access to suspend, makes life easier
     */
    status = pthread_mutex_lock (&susp_mut);
    if (status != 0)
        return status;

    /*
     * Threads that are suspended are added to the target_array;
     * a request to suspend a thread already listed in the array
     * is ignored. Sending a second SIGUSR1 would cause the
     * thread to re-suspend itself as soon as it is resumed.
     */
    while (i < susp_bottom) 
        if (susp_array[i++] == target_thread) {
            status = pthread_mutex_unlock (&susp_mut);
            return status;
        }

    /*
     * Ok, we really need to suspend this thread. So, lets find
     * the location in the array that we'll use. If we run off
     * the end, realloc the array for more space.
     */
    i = 0;
    while (susp_array[i] != 0)
        i++;

    if (i == susp_bottom) {
//        susp_array = (pthread_t*) realloc (
//            susp_array, (++susp_bottom * sizeof (pthread_t)));
//        if (susp_array == NULL) {
            pthread_mutex_unlock (&susp_mut);
            return errno;
//        }

//        susp_array[susp_bottom] = susp_null_pthread;   /* Clear new entry */
    }

    /*
     * Clear the sentinel and signal the thread to suspend.
     */
    susp_sentinel = 0;
    status = pthread_kill (target_thread, SIGUSR1);
    if (status != 0) {
        pthread_mutex_unlock (&susp_mut);
        return status;
    }

    /*
     * Wait for the sentinel to change.
     */
    while (susp_sentinel == 0)
        sched_yield ();
    
    susp_array[i] = target_thread;

    status = pthread_mutex_unlock (&susp_mut);
    return status;
}
/*
 * Suspend a thread by sending it a signal (SIGUSR1), which will
 * block the thread until another signal (SIGUSR2) arrives.
 *
 * Multiple calls to thd_suspend for a single thread have no
 * additional effect on the thread -- a single thd_continue
 * call will cause it to resume execution.
 */
Suspend a thread by sending it a signal (SIGUSR1), which will
block the thread until another signal (SIGUSR2) arrives.

Multiple calls to thd_suspend for a single thread have no
additional effect on the thread -- a single thd_continue
call will cause it to resume execution.
Suspend a thread by sending it a signal ( SIGUSR1 ) which will block the thread until another signal ( SIGUSR2 ) arrives . Multiple calls to thd_suspend for a single thread have no additional effect on the thread -- a single thd_continue call will cause it to resume execution .
int 
pthread_suspend (pthread_t target_thread)
{
    int status;
    int i = 0;
    status = pthread_once (&susp_once, suspend_init_routine);
    if (status != 0)
        return status;
    status = pthread_mutex_lock (&susp_mut);
    if (status != 0)
        return status;
    while (i < susp_bottom) 
        if (susp_array[i++] == target_thread) {
            status = pthread_mutex_unlock (&susp_mut);
            return status;
        }
    i = 0;
    while (susp_array[i] != 0)
        i++;
    if (i == susp_bottom) {
            pthread_mutex_unlock (&susp_mut);
            return errno;
    }
    susp_sentinel = 0;
    status = pthread_kill (target_thread, SIGUSR1);
    if (status != 0) {
        pthread_mutex_unlock (&susp_mut);
        return status;
    }
    while (susp_sentinel == 0)
        sched_yield ();
    susp_array[i] = target_thread;
    status = pthread_mutex_unlock (&susp_mut);
    return status;
}
int pthread_suspend ( pthread_t target_thread ) { int status ; int i = 0 ; status = pthread_once ( & susp_once , suspend_init_routine ) ; if ( status != 0 ) return status ; status = pthread_mutex_lock ( & susp_mut ) ; if ( status != 0 ) return status ; while ( i < susp_bottom ) if ( susp_array [ i ++ ] == target_thread ) { status = pthread_mutex_unlock ( & susp_mut ) ; return status ; } i = 0 ; while ( susp_array [ i ] != 0 ) i ++ ; if ( i == susp_bottom ) { pthread_mutex_unlock ( & susp_mut ) ; return errno ; } susp_sentinel = 0 ; status = pthread_kill ( target_thread , SIGUSR1 ) ; if ( status != 0 ) { pthread_mutex_unlock ( & susp_mut ) ; return status ; } while ( susp_sentinel == 0 ) sched_yield ( ) ; susp_array [ i ] = target_thread ; status = pthread_mutex_unlock ( & susp_mut ) ; return status ; }
Suspend a thread by sending it a signal (SIGUSR1), which will
 block the thread until another signal (SIGUSR2) arrives.
Suspend a thread by sending it a signal ( SIGUSR1 ) which will block the thread until another signal ( SIGUSR2 ) arrives .
//thd_suspend (pthread_t target_thread) /*
     * The first call to thd_suspend will initialize the
     * package.
     */ /* 
     * Serialize access to suspend, makes life easier
     */ /*
     * Threads that are suspended are added to the target_array;
     * a request to suspend a thread already listed in the array
     * is ignored. Sending a second SIGUSR1 would cause the
     * thread to re-suspend itself as soon as it is resumed.
     */ /*
     * Ok, we really need to suspend this thread. So, lets find
     * the location in the array that we'll use. If we run off
     * the end, realloc the array for more space.
     */ //        susp_array = (pthread_t*) realloc ( //            susp_array, (++susp_bottom * sizeof (pthread_t))); //        if (susp_array == NULL) { //        } //        susp_array[susp_bottom] = susp_null_pthread;   /* Clear new entry */ /*
     * Clear the sentinel and signal the thread to suspend.
     */ /*
     * Wait for the sentinel to change.
     */