Kevin Vance - Things I did instead of doing the jsync conduit: Made a big…

Entries | Archive | Friends | Friends' Friends | User Info

08:01 pm

Thursday, April 24th, 2003
Previous Entry Share Next Entry
Things I did instead of doing the jsync conduit:
  • Made a big sticker for my laptop that says "MY OTHER COMPUTER IS A BEOWULF CLUSTER". That makes up for how.. uh, speed challenged it is.
  • Read about wild monkey sex bonobo society. Bonobos are neat.
  • Realized that the pilot-link conduit isn't quite finished yet, and worked on that.

The one last problem with the pilot-link conduit is that if a network request takes too long, the HotSync will time out because no communication with the pilot is going on. Enter pthreads. I've never used pthreads before, but it seemed to be easier than I thought. Still, if you've ever done any threads programming, I'd appreciate a "*nod* you did it the right way".

When the Conduit object is created, it creates a mutex and launches a new thread. The mutex is locked whenever the main thread is communicating with the pilot. During network transactions, it's unlocked. The pinging thread looks like this:

void Conduit::ping()
{
	while(1) {
		sleep(5);
		pthread_testcancel();
		pthread_mutex_lock(&pinging);
		pi_tickle(sd);
		pthread_mutex_unlock(&pinging);
		pthread_testcancel();
	}
}

It actually seems to work. I firewalled out livejournal.com and ran ljsync. Every HTTP request timed out, but the HotSync process kept running til the end.

Link )Reply )

Comments
From: ex_md744
2003-04-24 05:18 pm (UTC)
I loathe primates and primate research.
(Reply) (Thread)
[User Picture]From: kvance
2003-04-24 11:45 pm (UTC)
How come? It's neat!
(Reply) (Parent) (Thread)
[User Picture]From: nearby
2003-04-24 05:20 pm (UTC)

You must mass-produce this laptop-sticker and sell it on the inter-web. You'll make millions.
(Reply) (Thread)
[User Picture]From: kvance
2003-04-24 05:26 pm (UTC)
I just ripped the idea off ThinkGeek. Except they put their ugly logo on theirs.
(Reply) (Parent) (Thread)
[User Picture]From: nearby
2003-04-24 05:27 pm (UTC)
You should put Ayn Rand's ugly face on yours!!
(Reply) (Parent) (Thread)
[User Picture]From: kvance
2003-04-24 05:33 pm (UTC)
Yes.. of course! This new design will revolutionize the sticker industry!
(Reply) (Parent) (Thread)
From: zixyer
2003-04-25 12:43 am (UTC)
You know, I was just using threads for my C# program. The debug build complained when I had a thread like that -- that ran in an infinite loop and would only terminate when the program was killed. So I think the accepted practice is to have some sort of mechanism to stop the thread when the program is finished, and then in your exit routine in the main program should wait for all the threads to finish (using the thread join function, not sure what pthreads's is called). So I know in C# or Java you'd replace that while(1) with while(isRunning), and then when the program finished it would just set isRunning to 0 and then wait for the loop to terminate. But I'm just being pedantic and I'm not even sure if the way you're doing it would be considered bad form by anybody. So I'm really just making an ass out of myself here. But I've been tutoring computer science at school for so long that my first impulse whenever someone asks a programming question is to answer it whether or not I know what the answer is. :)
(Reply) (Thread)
[User Picture]From: kvance
2003-04-25 09:20 am (UTC)
Hmm.. I do call pthread_testcancel() to see if the thread has been cancelled. Then in the destructor for Conduit, it cancels the thread and then joins it. So I think that does the same thing...
(Reply) (Parent) (Thread)