回复: How to make libpurple multi-thread?

sirtoozee sirtoozee at gmail.com
Sat Sep 29 01:43:37 EDT 2007


Hi Evan,

Thanks, and I DEBUG the multi-thread stuff in nullclient.c, but I have
to wait for a long time to receive the conversation message from the
account added the 2 MSN accounts.

And it is interesting to read the sourc code of libpurple ^_^

/* I use 2 MSN accounts */
 #define TEST_THREAD_NUM 2
 char *TestName[] = {
 "sirtoozee at hotmail.com",
 "libpurple at hotmail.com",
 NULL
 };
 char *TestPassword[] = {
 "123456",
 "123456",
 NULL
 };
/* Then use fake main to break the main loop based on POSIX pthread */
 void *
 FakeMain(void *i)
 {
 PurpleAccount *account;
 PurpleSavedStatus *status;
 int iter = *((int *) i);
 /* Create the account */
 account = purple_account_new(TestName[iter], "prpl-msn");
 /* Get the password for the account */
 purple_account_set_password(account, TestPassword[iter]);
 /* It's necessary to enable the account first. */
 purple_account_set_enabled(account, UI_ID, TRUE);
 /* Now, to connect the account(s), create a status and activate it. */
 status = purple_savedstatus_new(NULL, PURPLE_STATUS_AVAILABLE);
 purple_savedstatus_activate(status);
 connect_to_signals_for_demonstration_purposes_only();
 return NULL;
 }
int main()
 {
 int i;
 GMainLoop *loop = g_main_loop_new(NULL, FALSE);
 pthread_t tid[TEST_THREAD_NUM];
 pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
 init_libpurple();
 printf("libpurple initialized.\n");
 for (i = 0; i < TEST_THREAD_NUM; i++)
 {
 pthread_mutex_lock(&mutex);
 pthread_create(&tid[i], NULL, FakeMain, (void *) &i);
 pthread_mutex_unlock(&mutex);
 }
 for (i = 0; i < TEST_THREAD_NUM; i++)
 {
 pthread_join(tid[i], NULL);
 }
 pthread_mutex_destroy(&mutex);
 g_main_loop_run(loop);
 return 0;
 }

2007/9/29, Evan Schoenberg <evands at pidgin.im>:
>
> On Sep 28, 2007, at 9:37 PM, sirtoozee wrote:
>
> > Hi libpurple dude:
> >
> > In the wiki about libpurple
> > http://developer.pidgin.im/wiki/WhatIsLibpurple, it is NOT threaded
> > due to it uses the glib mainloop to do all the things.
> >
> > But I want to know how to use another way to handle all the things
> > without the glib mainloop, if I could re-write some core code.
> >
> > Thanks a lot!
>
> The WhatIsLibpurple's section about threading was partially misleading
> and partially incorrect. I've updated the page; let us know if it
> remains unclear.
>
> -Evan
>
>


-- 
An individual human existence should be like a river - small at first,
narrowly contained within its banks, and rushing passionately past
boulders and over waterfalls. Gradually the river grows wider, the
banks recede, the waters flow more quietly, and in the end, without
any visible break, they become merged in the sea, and painlessly lose
their individual being.




More information about the Devel mailing list