[ Previous ] [ Contents ] [ Index ] [ Next ]

Ns_BeginThread

Overview

Start a thread

Syntax

    int Ns_BeginThread(
    Ns_ThreadProc *start_routine, 
    void *arg, 
    Ns_Thread *thread
    );

Description

Ns_BeginThread starts a new thread running start_routine and passwd arg as its context. If thread is non-null it will be filled with the thread's id. (see Ns_WaitForThread.)

Ns_ThreadCreate is the preferred function to start a thread.

Examples

    static void
    ThreadStart(void *arg)
    {
    	int n;
    
    	n = (int) arg;
    	Ns_Log(Notice, "%d: %d", Ns_GetThreadId(), n);
    }
    
    /*
      * ManyThreadWait - Create 10 threads which all log a message
      * and wait for all of them to exit.
      */
    static void
    ManyThreadWait(void)
    {
    	int i;
    	Ns_Thread tids[10];
    
    	for (i = 0; i < 10; ++i) {
    		Ns_BeginThread(ThreadStart, (void *) i, &tids[i]);
    	}
    
    	for (i = 0; i < 10; ++i) {
    		Ns_WaitForThread(&tids[i]);
    	}
    }

Top of Page

[ Previous ] [ Contents ] [ Index ] [ Next ]
Copyright © 1998-99 America Online, Inc.