Glibc, _ read_nocancel, _ write_nocancel, and other function conflicts and call problems in the pthread Library

Source: Internet
Author: User
Tags valgrind

Start with a simple program:

#include <stdio.h>#include <fcntl.h>int main() {        FILE* fp = open("./1", O_WRONLY);        char a[100];        while (1){                write(fp,"aaaa",4);                read(fp, a, 100);        }        close(fp);}

Other sys calls are not read, mainly write and read. in Linux, the two are from the glibc library. Compile this program to check the function call status.

Pai_^ [/home/crazybaby/] # GCC main. c ^_^ [/home/crazybaby/] # valgrind -- tool = callgrind. out-> C-c ^_^ [/home/crazybaby/] # callgrind_annotate callgrind. out.9150... omitted... IR file: function ------------------------------------------------------------------------------------ 4,534,175 ??? : Main [/home/crazybaby/welcomec/a. Out] 4,534,167 ??? :__ Write_nocancel [/lib64/libc-2.5.so] 4,534,160 ??? :__ Read_nocancel [/lib64/libc-2.5.so] 824,404 ??? : Read [/lib64/libc-2.5.so] 824,394 ??? : Write [/lib64/libc-2.5.so]

It can be seen that the read and write operations are from libc during normal compilation (without the thread library pthread), and they are normal.

Let's see how to add-Pthread.

Pai_^ [/home/crazybaby/] # GCC main. c-lpthread pai_^ [/home/crazybaby/] # valgrind -- tool = callgrind. out-> C-c ^_^ [/home/crazybaby/] # callgrind_annotate callgrind. out.9150... omitted... IR file: function ------------------------------------------------------------------------------------ 2,769,176 ??? : Main [/home/crazybaby/welcomec/a. Out] 2,769,162 ??? :__ Read_nocancel [/lib64/libpthread-2.5.so] 2,769,162 ??? :__ Write_nocancel [/lib64/libpthread-2.5.so] 503,499 ??? : Read [/lib64/ld-2.5.so] 503,484 ??? : Write [/lib64/libpthread-2.5.so] 33,527 ??? : Do_lookup_x [/lib64/ld-2.5.so]

We can see that both write and read come from the libpthread library.

Solution:
Added the glibc dynamic library-LC to the display during compilation.

Pai_^ [/home/crazybaby/] # GCC main. c-LC-lpthread ^_^ [/home/crazybaby/] # valgrind -- tool = callgrind. out-> C-c ^_^ [/home/crazybaby/] # callgrind_annotate callgrind. out.9276... omitted... sort IR file: function ------------------------------------------------------------------------------------ 2,183,618 ??? : Main [/home/crazybaby/welcomec/a. Out] 2,183,610 ??? :__ Write_nocancel [/lib64/libc-2.5.so] 2,183,599 ??? :__ Read_nocancel [/lib64/libc-2.5.so] 397,033 ??? : Read [/lib64/libc-2.5.so] 397,020 ??? : Write [/lib64/libc-2.5.so] 28,297 ??? : Do_lookup_x [/lib64/ld-2.5.so] 22,899 ??? : _ Dl_lookup_symbol_x [/lib64/ld-2.5.so]

This morning I analyzed and found that pthread is part of glibc, so only the glibc library is required.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.