2005年12月29日

OK,基本上移植完毕,这几天的blog估计更新速度会很慢,也许明年才能正式开始,临近期末考试,每门功课都很紧张,要考试,要课程设计,要提交论文,累死累活的,寒假里还有好多的事情要做。

明年?元旦就要到了,明年!明年也许应该把blog改变一下风格了,每天都记,差不多都成了日记了,明年的blog要精益求精,以后就要靠通信吃饭了,在这个领域内扑腾了整整四年半了,感觉自己还是一个门外汉,也许是因为本科的时候基础没有太好,电子科技,涉及到的通信计算机并不多,不过没关系,才刚刚开始,一切都会向着美好转化……

当初选择了留在北邮读研,而不是去工作,就得有心理准备,这里牛人有很多,这里有足够的通信氛围,虽然大部分的牛导的心思大都不放在术上,北邮有成为北邮通信公司的倾向,但是不管是公司还是学术,北邮的在通信领域内的贡献功不可没,期望自己能够在这样一个大的环境下有所作为。寻找一且的机会提高自己的能力,不管是进公司实习还是在实验室coding,都是锻炼能力的地方,要以平常心来对待得失,一切只是你自己的态度问题……

通信的发展速度远远超出了我的想象,想象01年刚刚入学的时候,手机根本没有普及,201电话如火如荼,宿舍网基本没有铺全,大家千方百计地去机房占座位,或者用192拨号上网,3G,NGN,IPv6听都没有听说过,当时也不感兴趣,四年的时间,经历对通信一无所知到现在至少有了一个大概的轮廓,以后还有很长的一段路要走,通信,大有可为……

posix 线程编程
 
POSIX(可移植操作系统接口)线程是提高代码响应和性能的有力手段。在本系列中,Daniel Robbins 向您精确地展示在编程中如何使用线程。其中还涉及大量幕后细节,读完本系列文章,您完全可以运用 POSIX 线程创建多线程程序。
线程是有趣的
了解如何正确运用线程是每一个优秀程序员必备的素质。线程类似于进程。如同进程,线程由内核按时间分片进行管理。在单处理器系统中,内核使用时间分片来模拟线程的并发执行,这种方式和进程的相同。而在多处理器系统中,如同多个进程,线程实际上一样可以并发执行。
那么为什么对于大多数合作性任务,多线程比多个独立的进程更优越呢?这是因为,线程共享相同的内存空间。不同的线程可以存取内存中的同一个变量。所以,程序中的所有线程都可以读或写声明过的全局变量。如果曾用 fork() 编写过重要代码,就会认识到这个工具的重要性。为什么呢?虽然 fork() 允许创建多个进程,但它还会带来以下通信问题: 如何让多个进程相互通信,这里每个进程都有各自独立的内存空间。对这个问题没有一个简单的答案。虽然有许多不同种类的本地 IPC (进程间通信),但它们都遇到两个重要障碍:
强加了某种形式的额外内核开销,从而降低性能。
对于大多数情形,IPC 不是对于代码的“自然”扩展。通常极大地增加了程序的复杂性。
双重坏事: 开销和复杂性都非好事。如果曾经为了支持 IPC 而对程序大动干戈过,那么您就会真正欣赏线程提供的简单共享内存机制。由于所有的线程都驻留在同一内存空间,POSIX 线程无需进行开销大而复杂的长距离调用。只要利用简单的同步机制,程序中所有的线程都可以读取和修改已有的数据结构。而无需将数据经由文件描述符转储或挤入紧窄的共享内存空间。仅此一个原因,就足以让您考虑应该采用单进程/多线程模式而非多进程/单线程模式。
线程是快捷的
不仅如此。线程同样还是非常快捷的。与标准 fork() 相比,线程带来的开销很小。内核无需单独复制进程的内存空间或文件描述符等等。这就节省了大量的 CPU 时间,使得线程创建比新进程创建快上十到一百倍。因为这一点,可以大量使用线程而无需太过于担心带来的 CPU 或内存不足。使用 fork() 时导致的大量 CPU 占用也不复存在。这表示只要在程序中有意义,通常就可以创建线程。
当然,和进程一样,线程将利用多 CPU。如果软件是针对多处理器系统设计的,这就真的是一大特性(如果软件是开放源码,则最终可能在不少平台上运行)。特定类型线程程序(尤其是 CPU 密集型程序)的性能将随系统中处理器的数目几乎线性地提高。如果正在编写 CPU 非常密集型的程序,则绝对想设法在代码中使用多线程。一旦掌握了线程编码,无需使用繁琐的 IPC 和其它复杂的通信机制,就能够以全新和创造性的方法解决编码难题。所有这些特性配合在一起使得多线程编程更有趣、快速和灵活。
线程是可移植的
如果熟悉 Linux 编程,就有可能知道 __clone() 系统调用。__clone() 类似于 fork(),同时也有许多线程的特性。例如,使用 __clone(),新的子进程可以有选择地共享父进程的执行环境(内存空间,文件描述符等)。这是好的一面。但 __clone() 也有不足之处。正如__clone() 在线帮助指出:
“__clone 调用是特定于 Linux 平台的,不适用于实现可移植的程序。欲编写线程化应用程序(多线程控制同一内存空间),最好使用实现 POSIX 1003.1c 线程 API 的库,例如 Linux-Threads 库。参阅 pthread_create(3thr)。”
虽然 __clone() 有线程的许多特性,但它是不可移植的。当然这并不意味着代码中不能使用它。但在软件中考虑使用 __clone() 时应当权衡这一事实。值得庆幸的是,正如 __clone() 在线帮助指出,有一种更好的替代方案:POSIX 线程。如果想编写可移植的多线程代码,代码可运行于 Solaris、FreeBSD、Linux 和其它平台,POSIX 线程是一种当然之选。
第一个线程
下面是一个 POSIX 线程的简单示例程序:
thread1.c
#include
#include
#include
void *thread_function(void *arg) {
int i;
for ( i=0; i<20; i++) {
printf("Thread says hi!n");
sleep(1);
}
return NULL;
}
int main(void) {
pthread_t mythread;
if ( pthread_create( &mythread, NULL, thread_function, NULL) ) {
printf("error creating thread.");
abort();
}
if ( pthread_join ( mythread, NULL ) ) {
printf("error joining thread.");
abort();
}
exit(0);
}
要编译这个程序,只需先将程序存为 thread1.c,然后输入:
$ gcc thread1.c -o thread1 -lpthread
运行则输入:
$ ./thread1
理解 thread1.c
thread1.c 是一个非常简单的线程程序。虽然它没有实现什么有用的功能,但可以帮助理解线程的运行机制。下面,我们一步一步地了解这个程序是干什么的。main() 中声明了变量 mythread,类型是 pthread_t。pthread_t 类型在 pthread.h 中定义,通常称为“线程 id”(缩写为 "tid")。可以认为它是一种线程句柄。
mythread 声明后(记住 mythread 只是一个 "tid",或是将要创建的线程的句柄),调用 pthread_create 函数创建一个真实活动的线程。不要因为 pthread_create() 在 "if" 语句内而受其迷惑。由于 pthread_create() 执行成功时返回零而失败时则返回非零值,将 pthread_create() 函数调用放在 if() 语句中只是为了方便地检测失败的调用。让我们查看一下 pthread_create 参数。第一个参数 &mythread 是指向 mythread 的指针。第二个参数当前为 NULL,可用来定义线程的某些属性。由于缺省的线程属性是适用的,只需将该参数设为 NULL。
第三个参数是新线程启动时调用的函数名。本例中,函数名为 thread_function()。当 thread_function() 返回时,新线程将终止。本例中,线程函数没有实现大的功能。它仅将 "Thread says hi!" 输出 20 次然后退出。注意 thread_function() 接受 void * 作为参数,同时返回值的类型也是 void *。这表明可以用 void * 向新线程传递任意类型的数据,新线程完成时也可返回任意类型的数据。那如何向线程传递一个任意参数?很简单。只要利用 pthread_create() 中的第四个参数。本例中,因为没有必要将任何数据传给微不足道的 thread_function(),所以将第四个参数设为 NULL

2005-12-15
 
 
 
A Simple Review of This Term
 
A term is to be finished, A term is to be finished, A Review should be made. For the limitation of time, I will have detailed a record and  review later, maybe after the final exams.

These days I am busy preparing for the final exam. Have a review of the classes. Although some of them  is no use, I have had a not small harvest.
 
Distributed Computing:
CORBA, EJB, Web Service, XML
 
Protocol Project and Communication Software:
MSC and SDL of ITU-T. Some of the most important tools in the design of protocols. And the use of Telelogic’s SDT software using to program the flow chart.
 
Computer Networks:
Mr. Mayan’s class. Giving me a new  of computer networks, TCP/IP, Routing’s RIP and OSPF. Sharing his experiences in more than 20 years career in computer networks.
 
IN:
ASI.1 coding and the principle of Mobile Communication.
 
Next Generation Networks:
Actually I dont find the advantage of teaching of Mr.Susen. But I learn a lot in the course by myself. The architeture of the NGN, the softswitch acting as the kernal of NGN, Media Gateway, Access Gateway… And the according protocols, SIP, H.323, MGCP, MeGaCo/H.248…
 
Linux Programing:
Actually, I study Linux by myself, from the operation of the OS, the kernel, C programing, and the use of gcc and gdb…
 
Experiment of Computernetworks:
openh.323, learned nothing, except for the principle of ipphone based H.323
 
Architecture of Computer:
At first I study it full of heart, but soon find it a rubbish class, and the garbage teacher!

2005-12-14
 
 
 
There must be something wrong with my brain
 
This afternoon, I went to the school library to return some books so that I could borrow some new ones. I remembered that I had borrowed 9 books. And I returned 2 this time. So I could borrow 3 books this time.
 
While I went to the librarian, She said to me that I could borrow 2 books only. I explained to her that I had returned 2 books. I remembered I still could borrow 3 books. She let me check the  list of my record to find which book I returned that still in the record. What a joke. I forgot  the name of the book that I retured minutes ago!
 
Without any better method, I check the list of my record! This book that I have not finished, so that I would not returne it. And so it was with that one…
 
At last, all in vain. The true is that I made a mistake in 9 books. I had borrowed 10 books. There must be something wrong in my brain. 

2005-12-13
 
 
 
Why is A Movie?
 
Why is A Movie, not B Movie?
 
When I was reading throuth the ppt of NGN of Mr.Susen. By accident, I forget the meaning of "AAA", so I look it up in Baidu. Of course I get the answer. "AAA" means Authentication, Authorization, Accounting.
 
But what is more, I meet with some one talking about "A movie" in a forum, I record their conversation in English, just for fun:) We are all beyond 18 years old.
 
->Adult movie, movies are defined in classes, Adult move is adult only.
 
->American Movie, most of the kind of movies of high quality come from American, but not form Hollywood.
 
->AV, form japan, A Video, then to Taiwan, is A movie.
 
->"ah, ah, ah…" this kind of cry is popular in the sort of movies, that where the name come from.
 
->A is "甲" in Chinese, the first. So in chinese pronunciation, A movie is 甲片, similar to "Japan", because most of abnomal A movies are form Japan.
 
->"A", form the structure of the leter. It’s top is acuate, hinting up. It’s below is wide, means two legs…
 
->Uausally, a film has two disks, A disk and B disk. While the time of palapala is short, so that A movie is ususlly one disk, that is A movie.
 
->Then why A movie is usually called blue movie? A network-shrimp gives the fellowing answer:
In English "blue" is usually associated with unhappy feelings. "In a blue mood" or "having the blues" means a sad gloomy or depressed mood. Similar in meaning is "a blue Monday" — the first day of work or school after a pleasant, happy weekend. Example:"It was blue Monday and he just didn’t feel like going back to work."
 
Then just have a thought, after the blue working day, you are tired. While your wife asks to palapala with you. Without any interest, then you said to your wife, what about a blue film instead of palapala?
 
 

2005-12-12
 
 
 
XML, eXtensible Markup Language
 
As one of important technologies in distributed computing, XML is becoming more and more popular. Application push the technology, XML is pushed forward by the e-commerce.
 
XML, is similar with HTML, but is more senior than HTML. That is, HTML can’t adapted to the development of e-commerce, the application require the appearance of XML. As a new-appearing technology, AML has more advantages than HTML.
 
In my opinion, XML vs HTML is like JAVA vs C, one is extensible one is not, one is object oriented while one is process oriented. The orignal design decided that THML can’t be extended well. The result is that HTML becomes more and more fat, so that the system almost can’t stant it.
 
While in XML, it is extensible, that is simple. Simpty is beautiful. XML is not as complete as HTML. It is just a original language. As a sub-gather of SGML, XML is used to set up other markup language. That means a big family, XML, DTD, XSL, XML scheme, XML namespace, DOM, Xquery,  Xpath.
 
I don’t want to say a lot about the disadvantages of HTML, all of them decides that it will disappear in the stage of history. 

2005-12-10
 
 
 
GSM, almost as old as me
 
The Principle of GSM system

What a joke! The homework of Intelligent Networks is about Mobile Communication, giving the name of Mobile Intelligent Networks! So I have to do some study in GSM, one of most important technology in mobile communication.The fellowing is the summary of my whole studies, give your ideas if you find some fault in everything except of grammar:)

GSM, one of the two mobile techonlogy in 2G, has a long history. Four countries of north Europe summited a suggestion to CEPT(Conference Europe of Post and Telecommunications), suggesting to do some specification on the frequency of 900MHZ in 1982. In the same year GSM-Group Special Mobile was founded to set up the standards of digital cellular technology.

GSM standard includes two systems, GSM900 and DCS1800. The two systems have the same function, the difference is the frequency, GSM works in 900MHZ while DCS1800 works in 1800MHZ. Firstly, China used GSM900, with the explosive development of mobile communication, the primary GSM900 could’t meet the request, so that DCS1800 was used as a support. There is a two-frequency network. If a user using a two-frequency mobile station, he could tranfer between the two mode without any detection. Almost every cellphone commpany supports to two-frequency subscriber, Nokia, Motorola, Ericsson…

GSM digital cellular communication system is made up of several sub-systems such as MS(Mobile Station), BSS(Basic Sub-System), and NSS(Networks Sub-system). And the BSS includes BSC and BTS. The BSS includes OMC, MSC , HLR, VLR, AUC and EIR. Each part has a complex function, the following will give you a summary.

MS, that we usually call cellphone, is made up of a fake machine and a SIM card. The sim card is a ID of a user telling the difference between one user and another. Without a SIM card, a MS(Mobile Station) can’t get connection to the BSS, except for the emergency call.

BSS, that is the Basic Station, the tower. Between the BSS and MS, there is wireless microwave. A MS must keep connection with the BSS time to time, actually is to the

MSC. The BSS includes BTS and BSC. BTS is a receiver-submiter while the BSC is in charge of connecting the BSS and MSC. MSC(Mobile switching centre), can be thought of a heart of a little communication in some sense. Managing the BSSes and the MSes in its charge. A MSC has interfaces to HLR and VLR. HLR and VLR, their fuction is location. HLR’s area is lager than VLR.

HLR is in charge of serval MSCs. A MSC has one VLR. But a MSC can be connected with serval BSSes. A BSS connect with more MS.

AUC, is used to judged if a MS has the authentication to use the service. For example, when a MS rambles to another area, which is charged by another MSC, the MS must change its location information in the according MSC’s HLR and VLR, and finds in AUC if the MS has right to use the services.
 

2005-12-8 

 
 
Without any premonitions, here comes the terminal term! Too many thesises, too many experiments and the final exams! All comes! But I become more and more lazy! Damn it! The bad weather! The boring courses! Every morning I have to get up before 8 o’clock!
 
My master’s courses are going to finished. Any results? Just for the exam or for the score? But the pressure makes me to prepare for the final exams. I have no extra time to study something that actually interests me. Maybe it’s just a step, after the small step, everything will be new start!
 
OK, there are 5 papers, 2 experiments left, they are all needed to be finished in the coming month! What a diffcult project! Cheer up!

2005-12-7
 
 
 
New Generation ID cards
 
Keywords:
Beitaipingzhuang police station, New generation ID card, Golden Five Stars, Orange

Today, a little warmer than the last several days, we went to Beitaipingzhuang police station to take photos for the new generation ID card. I don’t know it is the 2G or 3G, maybe 4G… Things changes a lot! four years ago, the first time I came to Beijing,  they came to our school to take photos for us! But now…
 
Though several bystreet, dirty and narrow, easily to be lost in them, from right to left, we arrived the police station at last. Just for this or that reasons, I was a little late, too many persons are ahead me. So it took me almost two hours to finish the damn thing!
 
After that, we went to Golden five stars market, bought some VASEs, that is socks…and a black soft hat to defend myself from the cold wind everynight I riding back to Dayun village…
 
Oh, the orange, not the orange, but the orange. Do you understand? The kind of orange the must be cut to serval pieces, usually 4 or 8, before sending it to your mouth. Geez! so many, just 6 yuan!

2005-12-6
 
 
 
Can’t help falling in love 
 
Wise men say only fools rush in.
But i can’t help falling in love with you.
Shall i stay?
Would it be a sin?
If i can’t help falling in love with you.
Like a river flows surely to the sea.
Darling so it goes
Somethings are meant to be
Take my hand,
Take my whole life too.
For i can’t help falling in love with you.
 
I am not a fool, I don’t rush in. But I can’t help falling in love you, from that day on. Just like the sun and sunflower. The butterfly dancing among the flowers, a river flowing to the sea, nothing gonna change my love for you. Wherever i am, like a flame, I will light the moning sky of yours. No nightmare, no injury, I will be always beside you.
 
Darling, I love you. Every time I was angry with you, I love you. My girlfriend should be more excellent than others. Nothing gonna change my love for you, darling. I will keep you in my heart time to time. Because I want you to be my wife, a wife of lifetime. Believe me, trust me, love is all around you.