Threading assertion problem

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi:

I'm beginning to play around with threads and I always get this error:
"Calling pjlib from unknown/external thread. You must..."

Googling around I found it's a common mistake not calling
pj_thread_register, but I do that and I get the same error. In fact I
get the error in this line:

pool = pj_pool_create(mem, "piscinazoo", 4000, 4000, NULL);


The code I'm working on is really simple, I just want to print a
message from the created thread, to undrestand how it works, but I
can't figure out where my mistake is:

The code:

#include <pjlib.h>

static pj_caching_pool cp;

static void* thread_proc(int i)
{
        pj_thread_t *este_hilo;
        pj_thread_desc desc;
        pj_status_t status;

        status = pj_thread_register("hilo1234", desc, &este_hilo);
        if (status != PJ_SUCCESS) {
                printf("Error registrando el hilo.%s\n", status);
                return NULL;
        }

        printf("Soy el procedimiento del otro hiloooo: -- %i\n", i);
        pj_thread_sleep(2000);
        printf("He esperado 2 segundos!!\n");
        return;
}
int kosa(void)
{
        pj_pool_t *pool;
        pj_thread_t *hilo;
        pj_status_t status;
        int num = 666;

        printf("Prueba de Hilos.\n");

        pj_caching_pool cp;
        pj_caching_pool_init(&cp, &pj_pool_factory_default_policy, 0);
        pj_pool_factory *mem;
        mem = &cp.factory;
        pool = pj_pool_create(mem, "piscinazoo", 4000, 4000, NULL);
        printf("edededed\n");
        if (!pool) {
                printf("Error creando la piscina!\n");
                return -1;
        }
        status = pj_thread_create(pool, "pruebaHilo",
(pj_thread_proc*)&thread_proc, &num, PJ_THREAD_DEFAULT_STACK_SIZE, 0,
&hilo);
        if (status != PJ_SUCCESS) {
                printf("Error creando el hilo.\n");
                return -1;
        }
        printf("Soy el hilo principal!!\n");
        pj_thread_join(hilo);
        pj_pool_release(pool);
        return 0;
}
int main(void)
{
        printf("holaaaaaa!\n");
        int estado = kosa();
        printf("Estado: %i", estado);
        return 0;

}


Can anyone tell me where is my mistake? Thanks in advance.

Regards.



-- 
Sa?l -- "Nunca subestimes el ancho de banda de un cami?n lleno de disketes."
----------------------------------------------------------------
http://www.saghul.net/



[Index of Archives]     [Asterisk Users]     [Asterisk App Development]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [Linux API]
  Powered by Linux