• Linux Kernel Threads
  • The Flow Management Software Interface Creating Threads
  • The Disadvantages Of Traditional Multitasking




    Download 6,34 Mb.
    Pdf ko'rish
    bet38/203
    Sana10.01.2024
    Hajmi6,34 Mb.
    #134102
    1   ...   34   35   36   37   38   39   40   41   ...   203
    Bog'liq
    Linux This Book Includes 4 Manuscripts The Underground Bible

    The Disadvantages Of Traditional Multitasking
    Support For Linux
    Multithreading basics in the Linux kernel have not undergone the
    principle of changes since the clone () system call. In the meantime, Linux
    has evolved from an experimental system to an industry-wide system where
    enterprise-class heavy-duty applications are implemented.
    This use of the system has led to the implementation of multi-threaded high
    reliability and scalability. It became apparent that the clone () system call
    implementation did not meet these requirements. We had the full
    implementation of multithreaded processing facilities at STI in the nucleus.
    Flow control is part of the standard POSIX 1996 corresponding API was
    named streams POSIX.
    Linux Kernel Threads
    In addition to user processes and threads, Linux also supports a special kind
    of planned objects that are already known as kernel threads. Such flows are
    scheduled as normal processes and flows, each with its own id
    ( pid ). Differences of kernel threads from processes and user threads are
    that:
    ❖ 
    The flow functions for them are defined in the kernel code
    ❖ 
    They run only in kernel mode
    ❖ 
    Them inaccessible areas of memory ' memory allocated in user
    mode
    The Flow Management Software Interface
    Creating Threads


    To add a new thread to the current process, POSIX uses the pthread _ create
    () function with the following syntax:
    #include
    int pthread_create (pthread_t * th, pthread_attr * attr,
    void * (* thread_fun) (void *). void * arg);
    Consider the parameters of this function:
    ❖ 
    th is a pointer to a predefined structure of type pthread _ t which
    will then be passed to other functions of work with flows; then call the
    AI to handle the flow ( thread handle )
    ❖ 
    Attr is a pointer to a structure with flow attributes (you need to pass
    a null pointer to use the default attributes; some attributes will be
    reviewed later)
    ❖ 
    thread _ fun is a pointer to a stream function that should be
    described as 
    void * mythread_fun (void * value) 

    // executing the stream code 
    }
    ❖ 
    arg - the data passed to the stream function (there they will get a
    parameter value )
    An example of creating a POSIX stream:
    # include < pthread . h >
    // flow function
    void * thread_fun (void * num)
    {
    printf (" stream number % d \ n", (int) num);
    }
    // ……………………………
    pthread_ t th;
    // create the second thread


    pthread_create (& th, NULL, thread_fun, (void *) ++ thread_num);
    // there are two threads running in parallel
    The new thread begins to run in parallel with the thread that created it. For
    example, if a thread was created inside the main () function, then two
    threads would continue to execute: an original program executing
    the main () code and a new one.

    Download 6,34 Mb.
    1   ...   34   35   36   37   38   39   40   41   ...   203




    Download 6,34 Mb.
    Pdf ko'rish

    Bosh sahifa
    Aloqalar

        Bosh sahifa



    The Disadvantages Of Traditional Multitasking

    Download 6,34 Mb.
    Pdf ko'rish