2012年2月29日

volatile

摘要: volatile就象大家更熟悉的const一样,volatile是一个类型修饰符(type specifier)。它是被设计用来修饰被不同线程访问和修改的变量。如果没有volatile,基本上会导致这样的结果:要么无法编写多线程程序,要么编译器失去大量优化的机会。简单地说就是防止编译器对代码进行优化.比如如下程序: XBYTE[2]=0x55; XBYTE[2]=0x56; XBYTE[2]=0x57; XBYTE[2]=0x58; 如果对外部硬件上述四条语句分别表示不同的操作,会产生四种不同的动作,那么编译器就不能像对 待纯粹的程序那样对上述四条语句进行优化只认为XBYT... 阅读全文

posted @ 2012-02-29 11:31 Richard.FreeBSD 阅读(318) 评论(0) 推荐(0)

close(1) 1 to state stdout

摘要: Example 1: Reassign a file descriptor. The following example closes the file descriptor associated with standard output for the current process, re-assigns standard output to a new file descriptor, and closes the original file descriptor to clean up. This example assu... 阅读全文

posted @ 2012-02-29 10:38 Richard.FreeBSD 阅读(240) 评论(0) 推荐(0)

alarm() function

摘要: alarm(设置信号传送闹钟) 相关函数 signal,sleep表头文件 #include<unistd.h>定义函数 unsigned int alarm(unsigned int seconds);函数说明 alarm()用来设置信号SIGALRM在经过参数seconds指定的秒数后传送给目前的进程。如果参数seconds 为0,则之前设置的闹钟会被取消,并将剩下的时间返回。返回值 返回之前闹钟的剩余秒数,如果之前未设闹钟则返回0。代码#include<unistd.h>#include<signal.h>void handler() {printf( 阅读全文

posted @ 2012-02-29 10:30 Richard.FreeBSD 阅读(290) 评论(0) 推荐(0)

导航