On date Monday 2008-09-08 10:31:43 +0200, Stefano Sabatini wrote: > On date Monday 2008-09-08 10:08:39 +0200, Stefano Sabatini wrote: > > On date Friday 2008-09-05 12:10:10 +0200, Stefano Sabatini wrote: > > > On 9/5/08, Stefano Sabatini <[EMAIL PROTECTED]> wrote: > > > > Hi all, > > > > > > > > I have a multithreaded application, and I need to run the sofia-sip > > > > event loop not in the main process context, but in the context of a > > > > thread. > > > > > > > > I implemented it this way. > > > > I implemented a method Run() which instantiates the thread instance > > > > and makes it execute su_root_run(), and a Stop() method which > > > > executes su_root_break() and wait for the thread termination. > > > > > > > > Unfortunately this approach seems not to work, as I get this message > > > > from the sofia stack: > > > > nua(0x8729740): signal r_invite > > > > SIPEngineTest: su_base_port.c:322: su_base_port_run: Assertion > > > > `su_port_own_thread(self)' failed. > > > > > > > > and the process gets terminated by the SIGABRT signal. > > > > > > > > I'm currently stuck with it, can someone help/provide some hint? > > > > > > Do I need to use the interface defined in su_wait.h? > > > I was using the functions provided in another library for managing > > > threading. > > > > Well I read the documentation for su_wait.h but I stll can't figure > > out how to use it. > > > > Since there is no way to create explicitly a thread, I think the > > nearest think to the thread concept is the task, then I can't see any > > reference to mutexes so I have no idea about how synchronization may > > work here (mmh well should I use messages for that?). > > > > Please can someone suggest just a simple way to use the sofia API to > > create and run a thread? > > Here it is my first attempt at sofia threading: [...]
New try using su_task_execute this time. ----------------------8<------------------------------------- #include <stdio.h> #include <signal.h> #include <stdlib.h> #include <string.h> /* this defines the kind of magic to pass to the handler, contains the application context */ #define SU_ROOT_MAGIC_T void #include <sofia-sip/su.h> #include <sofia-sip/su_wait.h> int task_function(void* opaque) { int i; printf("click clack click clack...\n"); for (i=10; i > 0; i--) { sleep(1); printf("%d...\n", i); } printf("BOOM...\n"); return 0; } int main (int argc, char *argv[]) { su_root_t *root; /* Initialize Sofia-SIP library and create event loop */ su_init(); root = su_root_create(NULL); /* create a root object, don't pass to it any context */ /* enable threading, now su_clone_start will start a new thread */ if (!su_root_threading(root, 1)) { fprintf(stderr, "Failed to activate threading\n"); exit(1); } su_task_r task; su_task_init(task); /* init the task */ int task_ended = 0; if (su_task_execute(task, &task_function, NULL, &task_ended) < 0) { fprintf(stderr, "Failed to execute the task\n"); exit(1); } printf("main process thread...\n"); /* how can I understand when the task thread is terminated? * for now it will continue forever... */ while (1) sleep(1); /* Destroy allocated resources */ su_root_destroy(root); /* how to notify the main thread of the termination of the task thread? */ su_task_deinit(task); su_deinit(); exit(0); } ----------------------8<------------------------------------- This always crashes with this backtrace: (gdb) r [Thread debugging using libthread_db enabled] [New Thread 0xb7a576b0 (LWP 24551)] Program received signal SIGSEGV, Segmentation fault. [Switching to Thread 0xb7a576b0 (LWP 24551)] 0xb7ed4d84 in su_port_own_thread (self=0x0) at su_port.h:332 (gdb) bt #0 0xb7ed4d84 in su_port_own_thread (self=0x0) at su_port.h:332 #1 0xb7ed4d20 in su_task_execute (task=0xbfd724a8, function=0x80486f4 <task_function>, arg=0x0, return_value=0xbfd724a4) at su_root.c:338 #2 0x080487ec in main () at su-thread4.c:42 Ideas? TIA, regards (and sorry for the mails flood). ------------------------------------------------------------------------- This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/ _______________________________________________ Sofia-sip-devel mailing list Sofia-sip-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/sofia-sip-devel