Re: [Linux-programlama] pthread.h

---------

New Message Reply About this list Date view Thread view Subject view Author view Attachment view

From: Tufan BIYIKTAS (tufan.biyiktas@gmail.com)
Date: Wed 18 May 2005 - 14:58:36 EEST


http://www.cs.cf.ac.uk/Dave/C/ sayfasindan alinti:

  Compiling a Multithreaded Application

There are many options to consider for header files, define flags, and
linking.

    Preparing for Compilation

The following items are required to compile and link a multithreaded
program.

    * A standard C compiler (cc, gcc /etc/)
    * Include files:
          o <thread.h> and <pthread.h>
          o <errno.h>, <limits.h>, <signal.h>, <unistd.h>
      ......

The include file <pthread.h>, used with the -lpthread library, compiles
code that is conformant with the multithreading interfaces defined by
the POSIX 1003.1c standard.
.......
Do not link a /nonthreaded/ program with -lthread or -lpthread. Doing so
establishes multithreading mechanisms at link time that are initiated at
run time. These /slow down/ a single-threaded application, waste system
resources, and produce misleading results when you debug your code

    Debugging a Multithreaded Program

The following list points out some of the more frequent oversights and
errors that can cause bugs in multithreaded programs.

    * Passing a pointer to the caller's stack as an argument to a new
      thread.
    * Accessing global memory (shared changeable state) without the
      protection of a synchronization mechanism.
    * Creating deadlocks caused by two threads trying to acquire rights
      to the same pair of global resources in alternate order (so that
      one thread controls the first resource and the other controls the
      second resource and neither can proceed until the other gives up).
    * Trying to reacquire a lock already held (recursive deadlock).
    * Creating a hidden gap in synchronization protection. This is
      caused when a code segment protected by a synchronization
      mechanism contains a call to a function that frees and then
      reacquires the synchronization mechanism before it returns to the
      caller. The result is that it appears to the caller that the
      global data has been protected when it actually has not.
    * Mixing UNIX signals with threads -- it is better to use the
      sigwait() model for handling asynchronous signals.
    * Forgetting that default threads are created
      PTHREAD_CREATE_JOINABLE and must be reclaimed with pthread_join().
      *Note*, pthread_exit() does not free up its storage space.
    * Making deeply nested, recursive calls and using large automatic
      arrays can cause problems because multithreaded programs have a
      more limited stack size than single-threaded programs.
    * Specifying an inadequate stack size, or using non-default stacks.
      And, note that multithreaded programs (especially those containing
      bugs) often behave differently in two successive runs, given
      identical inputs, because of differences in the thread scheduling
      order.

In general, multithreading bugs are statistical instead of
deterministic. Tracing is usually a more effective method of finding
order of execution problems than is breakpoint-based debugging.

alper yuce wrote:

> tesekkurler cevap icin..
> bu sorun hallolunca baska bir seyi bulam?yor..
> /usr/lib/libphread.a bu library nin kullandigi diger libraryler neler ?
> genel olarak bu sorunu nas?l cozebilirim.zincirleme biseylere
> gereksinim duyuyor.ve nerde oldugunu soylemiyor..
> iyi calismalar..
>
> */Tufan BIYIKTAS <tufan.biyiktas@gmail.com>/* wrote:
>
> gcc -o prog rprog.c -lpthread
>
> alper yuce wrote:
>
>> Bir tane projemiz var ve projede "pthread_create" fonksiyonunu
>> kullanmamiz gerekiyor. (Bu fonksiyon pthread.h bas,lik dosyasinda
>> tanimli. ) Fakat ben bunu include etmeme ragmen link zamaninda
>> onu gormuyor . s,öyle bir hata veriyor:
>>
>> "undefined reference to pthread_create"
>>
>> Bunun hakkinda bir bilgisi olan var mi?
>>
>> tesekkurler ,
>>
>> __________________________________________________
>> Do You Yahoo!?
>> Tired of spam? Yahoo! Mail has the best spam protection around
>> http://mail.yahoo.com
>>
>>------------------------------------------------------------------------
>>
>>_______________________________________________
>>Linux-programlama mailing list
>>Linux-programlama@liste.linux.org.tr
>>http://liste.linux.org.tr/mailman/listinfo/linux-programlama
>>
>>
>
> _______________________________________________
> Linux-programlama mailing list
> Linux-programlama@liste.linux.org.tr
> http://liste.linux.org.tr/mailman/listinfo/linux-programlama
>
> ------------------------------------------------------------------------
> Do you Yahoo!?
> Yahoo! Small Business - Try our new resources site!
> <http://us.rd.yahoo.com/evt=31637/*http://smallbusiness.yahoo.com/resources/>
>
>
>------------------------------------------------------------------------
>
>_______________________________________________
>Linux-programlama mailing list
>Linux-programlama@liste.linux.org.tr
>http://liste.linux.org.tr/mailman/listinfo/linux-programlama
>
>

_______________________________________________
Linux-programlama mailing list
Linux-programlama@liste.linux.org.tr
http://liste.linux.org.tr/mailman/listinfo/linux-programlama


New Message Reply About this list Date view Thread view Subject view Author view Attachment view

---------

Bu arsiv hypermail 2.1.2 tarafindan uretilmistir.