URL: https://www.opennet.ru/cgi-bin/openforum/vsluhboard.cgi
Форум: vsluhforumID9
Нить номер: 8391
[ Назад ]

Исходное сообщение
"pthread_create возвращает 11"

Отправлено and73y , 10-Авг-09 15:11 
Собрал кросс-gcc компилятор под Powerpc, проверил на простом примере - работает.
Написал примерчик с потоками:
#include <pthread.h>
#include <stdio.h>
#include <errno.h>
extern int errno;

void* print_xs(void* unused)
{
    while(1)
        printf("%s",'x');
    return NULL;
}

int main(int argc, void** argv)
{
    pthread_t thr;
    int thr_create_res = pthread_create(&thr, NULL, &print_xs, NULL);
    if (thr_create_res == 0){
        while(1)
            printf("%s",'o');
    }
    else{
        printf("last err: %d\n", errno);
        printf("thread create err: %d\n", thr_create_res);
    }
    return 0;
}

Собрал:
gcc -c threads.cpp
gcc -o threads threads.o -lpthread

Запускаю на TARGET машине:
last err: 4
thread create err: 11

В чем может быть причина?


Содержание

Сообщения в этом обсуждении
"pthread_create возвращает 11"
Отправлено phpcoder , 10-Авг-09 21:49 
>thread create err: 11
>
>В чем может быть причина?

Возможно, что strerror(11) подскажет вам больше.


"pthread_create возвращает 11"
Отправлено and73y , 11-Авг-09 08:49 
>>thread create err: 11
>>
>>В чем может быть причина?
>
>Возможно, что strerror(11) подскажет вам больше.

тогда уж
strerror(4);)

А вообще man pthread_create выдает следующие описание ошибки:
EAGAIN
Insufficient resources to create another thread, or a system-imposed limit on the number of threads was encountered. The latter case may occur in two ways: the RLIMIT_NPROC soft resource limit (set via setrlimit(2)), which limits the number of process for a real user ID, was reached; or the kernel's system-wide limit on the number of threads, /proc/sys/kernel/threads-max, was reached.

1. Ресурсы хватит точно, перед запуском проги убил 5 ненужных процессов.
2. /proc/sys/kernel/threads-max - файлик проверил - там 128.
3. Проверил RLIMIT_NPROC:
        struct rlimit rlp;
    int res = getrlimit(RLIMIT_NPROC, &rlp);
    printf("getrlimit result: %d\n", res);
    printf("soft limit: %d\n", rlp.rlim_cur);    
    printf("hard limit: %d\n", rlp.rlim_max);    

Результат:
getrlimit result: 0
soft limit: 64
hard limit: 64

Почему же все-таки не получается создать поток?


"pthread_create возвращает 11"
Отправлено San , 28-Окт-13 03:55 
>   printf("%s",'x');
>    printf("%s",'o');

Вот эти строки не смущают? Либо %c и 'x', либо %s и "x"! С этого надо бы начать... )