linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Good book
@ 2005-05-24  3:47 Ram S
  2005-05-24  5:06 ` lk
  2005-05-25  7:08 ` kerel level threads K. Anantha Kiran
  0 siblings, 2 replies; 6+ messages in thread
From: Ram S @ 2005-05-24  3:47 UTC (permalink / raw)
  To: linux-c-programming

Hi,
I am a new to linux. While going through the kernel
code, I saw couple of routines beginning with __ e.g
 __init free_all_bootmem_core (in mm/bootmem.c). Any 
specific reason why it is so ? I know this may be a 
very basic thing that I am asking and I need to to
read more. Can you point to me some good book which
I can refer and get some of the basic doubts 
clarified ?

Thanks,
Ram.



		
__________________________________ 
Do you Yahoo!? 
Yahoo! Small Business - Try our new Resources site
http://smallbusiness.yahoo.com/resources/

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Good book
  2005-05-24  3:47 Good book Ram S
@ 2005-05-24  5:06 ` lk
  2005-05-25  7:08 ` kerel level threads K. Anantha Kiran
  1 sibling, 0 replies; 6+ messages in thread
From: lk @ 2005-05-24  5:06 UTC (permalink / raw)
  To: Ram S, linux-c-programming

>I am a new to linux. While going through the kernel
>code, I saw couple of routines beginning with __ e.g
> __init free_all_bootmem_core (in mm/bootmem.c). Any
>specific reason why it is so ?

usually the methods starting with __ are the core routines & there would be
some wrapper to it..
say do_page_fault();  is a wrapper which internally calls __do_page_fault();

The __init token in the definition may look a little strange; it is a hint
to the kernel that the given function is
used only at initialization time. The module loader drops the initialization
function after the module is loaded, making its memory available for other
uses.
There is a similar tag (__initdata)for data used only during initialization.

You may also encounter __devinit and __devinitdata in the kernel source;
these translate to __init and __initdata only if the kernel has not been
configured for
hotpluggable devices.

>I know this may be a
>very basic thing that I am asking and I need to to
>read more. Can you point to me some good book which
>I can refer and get some of the basic doubts
>clarified ?

1] "Understanding the linux kernel" by "Bovet & Cesati " is a good book to
get the insight of kernel...
you can also look at some ebooks like..
2] Linux Kernel 2.4 Internals by Tigran Aivazian tigran@veritas.com
http://www.linuxdoc.org/guides.html
3]Linux Kernel Hackers Guide..

regqrds
lk



^ permalink raw reply	[flat|nested] 6+ messages in thread

* kerel level threads
  2005-05-24  3:47 Good book Ram S
  2005-05-24  5:06 ` lk
@ 2005-05-25  7:08 ` K. Anantha Kiran
  2005-05-25  9:06   ` Steven Smith
  2005-05-25 11:46   ` Glynn Clements
  1 sibling, 2 replies; 6+ messages in thread
From: K. Anantha Kiran @ 2005-05-25  7:08 UTC (permalink / raw)
  To: linux-c-programming

Hi all,
    Point me to appropiate group if this question doesnt fit here.
    Does pthread_create() create kernel level threads?
    I have created two threads A and B. Thread A was written to print 
some statement in an infinite loop, while Thread B was written to be 
blocked for some time(I have used sleep system call to block Thread B). 
If at all pthread_create() creates user level threads, Blocking of 
Thread B will also make Thread A to be blocked.  But  in my output, 
Thread A was continously printing even when Thread B was blocked.  My 
observation is that either both of the threads be Kernel level threads 
or pthread library has given wrapper functions for blocking calls(for 
example, sleep system call in our case) which stop all of the threads to 
be blocked.  I read in text books that pthread libray is for creating 
user level threads(threads about which kernel is not aware of).

       I coudnt find the source for pthread library to clarify above 
doubts. Please help me in this.

Regards,
Ananth
----------------------------
My program:

#include <stdio.h>
#include <pthread.h>
#include <unistd.h>
// this function continously prints messages
// in order to show its execution
void* f (void* a) {
    while (1)
        printf ("f():\n");
    return NULL;
}
// this functin sleeps for some time
void* g (void* b) {
    printf ("g():\n");
    sleep (1);
    printf ("g(): sleeping over\n");
    return NULL;
}
int main (void) {
    pthread_t thread1,thread2;
    //creating thread to print messages
    if (pthread_create (&thread1, NULL, (void*)f, NULL)) {
        perror("pthread_create():");
        pthread_exit(NULL);
    }
    // creating thread to sleep(or block) for a while
    if (pthread_create (&thread2, NULL, (void*)g, NULL)) {
        perror("pthread_create():");
        pthread_exit(NULL);
    }
    printf ("main thread pid %d\n", getpid());
    pthread_exit(NULL);
}

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: kerel level threads
  2005-05-25  7:08 ` kerel level threads K. Anantha Kiran
@ 2005-05-25  9:06   ` Steven Smith
  2005-05-25 11:46   ` Glynn Clements
  1 sibling, 0 replies; 6+ messages in thread
From: Steven Smith @ 2005-05-25  9:06 UTC (permalink / raw)
  To: K. Anantha Kiran; +Cc: linux-c-programming, sos22

[-- Attachment #1: Type: text/plain, Size: 939 bytes --]

>    Does pthread_create() create kernel level threads?
Undefined.  Whether the kernel knows about the threads is up to the
implementation of the threading library.  Usually, on Linux, there is
one kernel thread for every user thread.

> My observation is that either both of the threads be Kernel level
> threads or pthread library has given wrapper functions for blocking
> calls(for example, sleep system call in our case) which stop all of
> the threads to be blocked.
Either would be an acceptable implementation.  Linux pthreads takes
the former approach.

> I read in text books that pthread libray is for creating user level
> threads(threads about which kernel is not aware of).
There are (at least) two different meanings of user-level threads.
pthread_create creates a user-level thread in the sense that it runs
user-level code, but the details of who makes the scheduling decisions
are left up to the implementation.

Steven.

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: kerel level threads
  2005-05-25  7:08 ` kerel level threads K. Anantha Kiran
  2005-05-25  9:06   ` Steven Smith
@ 2005-05-25 11:46   ` Glynn Clements
  2005-05-25 11:57     ` Glynn Clements
  1 sibling, 1 reply; 6+ messages in thread
From: Glynn Clements @ 2005-05-25 11:46 UTC (permalink / raw)
  To: K. Anantha Kiran; +Cc: linux-c-programming


K. Anantha Kiran wrote:

>     Point me to appropiate group if this question doesnt fit here.
>     Does pthread_create() create kernel level threads?
>     I have created two threads A and B. Thread A was written to print 
> some statement in an infinite loop, while Thread B was written to be 
> blocked for some time(I have used sleep system call to block Thread B). 
> If at all pthread_create() creates user level threads, Blocking of 
> Thread B will also make Thread A to be blocked.  But  in my output, 
> Thread A was continously printing even when Thread B was blocked.  My 
> observation is that either both of the threads be Kernel level threads 
> or pthread library has given wrapper functions for blocking calls(for 
> example, sleep system call in our case) which stop all of the threads to 
> be blocked.  I read in text books that pthread libray is for creating 
> user level threads(threads about which kernel is not aware of).

libpthread creates kernel threads.

-- 
Glynn Clements <glynn@gclements.plus.com>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: kerel level threads
  2005-05-25 11:46   ` Glynn Clements
@ 2005-05-25 11:57     ` Glynn Clements
  0 siblings, 0 replies; 6+ messages in thread
From: Glynn Clements @ 2005-05-25 11:57 UTC (permalink / raw)
  To: K. Anantha Kiran, linux-c-programming


Glynn Clements wrote:

> >     Point me to appropiate group if this question doesnt fit here.
> >     Does pthread_create() create kernel level threads?
> >     I have created two threads A and B. Thread A was written to print 
> > some statement in an infinite loop, while Thread B was written to be 
> > blocked for some time(I have used sleep system call to block Thread B). 
> > If at all pthread_create() creates user level threads, Blocking of 
> > Thread B will also make Thread A to be blocked.  But  in my output, 
> > Thread A was continously printing even when Thread B was blocked.  My 
> > observation is that either both of the threads be Kernel level threads 
> > or pthread library has given wrapper functions for blocking calls(for 
> > example, sleep system call in our case) which stop all of the threads to 
> > be blocked.  I read in text books that pthread libray is for creating 
> > user level threads(threads about which kernel is not aware of).
> 
> libpthread creates kernel threads.

By which I mean that the kernel creates additional "tasks" using
clone(). The new tasks have their own kernel-level data (signal masks
etc) and are scheduled by the kernel.

There are threading libraries which don't require any support from the
kernel, but are implemented entirely in user-space. That isn't how the
pthread library is implemented.

On Linux, the term "kernel thread" can also refer to threads which
execute entirely within the kernel. The pthread library doesn't have
anything to do with those.

-- 
Glynn Clements <glynn@gclements.plus.com>

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2005-05-25 11:57 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-05-24  3:47 Good book Ram S
2005-05-24  5:06 ` lk
2005-05-25  7:08 ` kerel level threads K. Anantha Kiran
2005-05-25  9:06   ` Steven Smith
2005-05-25 11:46   ` Glynn Clements
2005-05-25 11:57     ` Glynn Clements

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).