Главная страница


ru.linux

 
 - RU.LINUX ---------------------------------------------------------------------
 From : Dmitri Bogutski                      2:5020/400     08 Oct 2001  13:20:17
 To : All
 Subject : pthread & HPUX
 -------------------------------------------------------------------------------- 
 
 Hi!
 
 have the following code:
 #include <pthread.h>
 #undef _INCLUDE_POSIX1C_SOURCE
 #include <unistd.h>
 #include <malloc.h>
 
 pthread_mutex_t mutex;
 pthread_mutex_t m2;
 int mcount;
 
 class Client {
     public:
         Client () {};
         ~Client() {};
         int m;
 };
 
 void *threadrun (void *thr) {
     int i;
     Client *c;
     for (i=1;i<100;i++) {
       if (1==1) {
         pthread_mutex_lock (&mutex);
         c = new Client();
         pthread_mutex_unlock (&mutex);
         delete c;
       }
     }
     pthread_mutex_lock(&m2);
     mcount--;
     pthread_mutex_unlock(&m2);
     return NULL;
 }
 
 int main () {
 
     int i;
     pthread_t thr[10];
 
     pthread_mutex_init (&mutex, NULL);
     pthread_mutex_init (&m2, NULL);
 
     for (i=0;i<10;i++) {
       pthread_mutex_lock (&m2);
       mcount++;
       pthread_mutex_unlock (&m2);
       pthread_create (&thr[i], 0, threadrun, NULL);
     }
 
     for (;mcount>0;sleep(1));
 
     pthread_mutex_destroy (&mutex);
 }
 HPUX-11 / 2CPU will get segfault about 80% runs at the line 'c=new
 Client()'
 
 [/tests]uname -a
 HP-UX ns B.11.00 U 9000/800 610339382 unlimited-user license
 [/tests]gcc -v
 Reading specs from
 /opt/gcc/lib/gcc-lib/hppa2.0n-hp-hpux11.00/2.95.2/specs
 gcc version 2.95.2 19991024 (release)
 [/tests]
 
 I build it this way: gcc a.cpp -lpthread -DREENTRANT -ggdb
 
 is working under linux.
 
 do you have any ideas?
 -- 
 Dmitry Bogutsky
 diman@tradenet.ee
 --- ifmail v.2.15dev5
  * Origin: Tradenet Systems (2:5020/400)
 
 

Вернуться к списку тем, сортированных по: возрастание даты  уменьшение даты  тема  автор 

 Тема:    Автор:    Дата:  
 pthread & HPUX   Dmitri Bogutski   08 Oct 2001 13:20:17 
 Re: pthread & HPUX   yx   08 Oct 2001 23:23:50 
Архивное /ru.linux/526779225068.html, оценка 2 из 5, голосов 10
Яндекс.Метрика
Valid HTML 4.01 Transitional