Monday, December 6, 2010

Thread for perl---learn this week

I alway want to learn how to use thread. This semester, I am working on a project, and the project needs to run blastx on 5000 genes, it takes me almost 3 days. Besides taking a long time, it also very risky since it's easy to broken when you run blastx such a long time. And this week, I learned how to use multiple thread in perl. There are a lot of things if you want to go deep into thread. Here, I just write the basic things that we can use threads quickly.

1. claim the package at the beginning: use thread;

2. construct thread object use: $thread=threads->new(sub routine, parameters of sub routine). Here, we only construct the thread object, but we did not run the subroutine.

3. run the thread one by one: $thread->join.

Actually, there are a lot of tricky things for thread, you can even write a book about thread. My experience tells me the best way to learn coding is reading other's code and coding by yourself. When I learned C++ in my undergraduate school, they always need you to read book and remember some rules, and take the exam about the rules. I just feel it's not very helpful. I think in the work, we need to learn things very quickly, and the fastest way to learn things is watching how others do it and mimic and practice. 

No comments:

Post a Comment