LinuxϵÄC±à³ÌÈëÃÅÖ®¡°Ï̡߳±¿ØÖÆÓë¡°Ï̡߳±Í¨Ðűà³Ì
±¾ÎÄÀ´×Ô:Linux½Ì³Ì -- http://doc.linuxpk.com/53295.html
ÈçÓв»Ã÷°×Ö®´¦£¬»¶Ó²Î¼ÓÉçÇøÌÖÂÛ
1.Linux“Ï߳̔
±ÊÕßÔø¾ÔÚ¡¶»ùÓÚǶÈëʽ²Ù×÷ϵͳVxWorksµÄ¶àÈÎÎñ²¢·¢³ÌÐòÉè¼Æ¡·£¨¡¶Èí¼þ±¨¡·2006ÄêµÚ5~12ÆÚ£©ÖÐÏêϸÐðÊöÁ˽ø³ÌºÍÏ̵߳ÄÇø±ð£¬²¢Ôø¾ËµÃ÷LinuxÊÇÒ»ÖÖ“¶à½ø³Ìµ¥Ï߳̔µÄ²Ù×÷ϵͳ¡£Linux±¾ÉíÖ»Óнø³ÌµÄ¸ÅÄ¶øÆäËùνµÄ“Ï߳̔±¾ÖÊÉÏÔÚÄÚºËÀïÈÔÈ»Êǽø³Ì¡£´ó¼ÒÖªµÀ£¬½ø³ÌÊÇ×ÊÔ´·ÖÅäµÄµ¥Î»£¬Í¬Ò»½ø³ÌÖеĶà¸öÏ̹߳²Ïí¸Ã½ø³ÌµÄ×ÊÔ´£¨Èç×÷Ϊ¹²ÏíÄÚ´æµÄÈ«¾Ö±äÁ¿£©¡£LinuxÖÐËùνµÄ“Ïֻ߳̔ÊÇÔÚ±»´´½¨µÄʱºò“¿Ë¡”(clone)Á˸¸½ø³ÌµÄ×ÊÔ´£¬Òò´Ë£¬clone³öÀ´µÄ½ø³Ì±íÏÖΪ“Ï߳̔£¬ÕâÒ»µãÒ»¶¨ÒªÅªÇå³þ¡£ LinuxÄÚºËÖ»ÌṩÁËÇáÁ¿½ø³ÌµÄÖ§³Ö£¬Î´ÊµÏÖÏß³ÌÄ£ÐÍ£¬µ«Linux¾¡×î´óŬÁ¦ÓÅ»¯Á˽ø³ÌµÄµ÷¶È¿ªÏú£¬ÕâÔÚÒ»¶¨³Ì¶ÈÉÏÃÖ²¹ÎÞÏ̵߳ÄȱÏÝ¡£LinuxÓÃÒ»¸öºËÐĽø³Ì£¨ÇáÁ¿½ø³Ì£©¶ÔÓ¦Ò»¸öỊ̈߳¬½«Ï̵߳÷¶ÈµÈͬÓÚ½ø³Ìµ÷¶È£¬½»¸øºËÐÄÍê³É¡£
Ä¿Ç°LinuxÖÐ×îÁ÷ÐеÄÏ̻߳úÖÆΪLinuxThreads£¬Ëù²ÉÓõľÍÊÇỊ̈߳½ø³Ì“Ò»¶ÔÒ»”Ä£ÐÍ£¬µ÷¶È½»¸øºËÐÄ£¬¶øÔÚÓû§¼¶ÊµÏÖÒ»¸ö°üÀ¨ÐźŴ¦ÀíÔÚÄÚµÄÏ̹߳ÜÀí»úÖÆ¡£LinuxThreadsÓÉXavier Leroy (Xavier.Leroy@inria.fr)¸ºÔ𿪷¢Íê³É£¬²¢ÒÑ°ó¶¨ÔÚGLIBCÖз¢ÐУ¬ËüʵÏÖÁËÒ»ÖÖBiCapitalizedÃæÏòLinuxµÄPosix 1003.1c “pthread”±ê×¼½Ó¿Ú¡£Linuxthread¿ÉÒÔÖ§³ÖIntel¡¢Alpha¡¢MIPSµÈƽ̨ÉϵĶദÀíÆ÷ϵͳ¡£
°´ÕÕPOSIX 1003.1c ±ê×¼±àдµÄ³ÌÐòÓëLinuxthread ¿âÏàÁ´½Ó¼´¿ÉÖ§³ÖLinuxƽ̨ÉϵĶàỊ̈߳¬ÔÚ³ÌÐòÖÐÐè°üº¬Í·Îļþpthread. h£¬ÔÚ±àÒëÁ´½ÓʱʹÓÃÃüÁ
gcc -D -REENTRANT -lpthread xxx. c
ÆäÖÐ-REENTRANTºêʹµÃÏà¹Ø¿âº¯Êý(Èçstdio.h¡¢errno.hÖк¯Êý) ÊÇ¿ÉÖØÈëµÄ¡¢Ḭ̈߳²È«µÄ(thread-safe)£¬-lpthreadÔòÒâζ×ÅÁ´½Ó¿âĿ¼ÏµÄlibpthread.a»òlibpthread.soÎļþ¡£Ê¹ÓÃLinuxthread¿âÐèÒª2.0ÒÔÉÏ°æ±¾µÄLinuxÄں˼°ÏàÓ¦°æ±¾µÄC¿â(libc 5.2.18¡¢libc 5.4.12¡¢libc 6)¡£
2.“Ï߳̔¿ØÖÆ
Ï̴߳´½¨
½ø³Ì±»´´½¨Ê±£¬ÏµÍ³»áΪÆä´´½¨Ò»¸öÖ÷Ị̈߳¬¶øÒªÔÚ½ø³ÌÖд´½¨ÐµÄỊ̈߳¬Ôò¿ÉÒÔµ÷ÓÃpthread_create£º
pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *
(start_routine)(void*), void *arg);
start_routineΪÐÂÏ̵߳ÄÈë¿Úº¯Êý£¬argΪ´«µÝ¸østart_routineµÄ²ÎÊý¡£
ÿ¸öÏ̶߳¼ÓÐ×Ô¼ºµÄÏß³ÌID£¬Ò
Ïà¹ØÎĵµ£º
C×Ö·û´®´¦Àíº¯ÊýµÄʵÏÖ£¨Linux£©
#include <stddef.h>
char * ___strtok = NULL;
char * strcpy(char * dest,const char *src)
{
char *tmp = dest;
while ((*dest++ = *src++) != '\0')
/* nothing */;
return tmp;
}
char * strncpy(char * dest,const char *src,size_t count)
{
char *tmp = d ......
1£® ÔÚCÓïÑÔÖÐÄÚǶ»ã±à
ÔÚCÖÐÄÚǶµÄ»ã±àÖ¸Áî°üº¬´ó²¿·ÖµÄARMºÍThumbÖ¸Á²»¹ýÆäʹÓÃÓë»ã±àÎļþÖеÄÖ¸ÁîÓÐЩ²»Í¬£¬´æÔÚһЩÏÞÖÆ£¬Ö÷ÒªÓÐÏÂÃ漸¸ö·½Ã棺
a. ²»ÄÜÖ±½ÓÏòPC¼Ä´æÆ÷¸³Öµ£¬³ÌÐòÌøתҪʹÓÃB»òÕßBLÖ¸Áî
b. ÔÚʹÓÃÎïÀí¼Ä´æÆ÷ʱ£¬²»ÒªÊ¹ÓùýÓÚ¸´ÔÓµÄC±í´ïʽ£¬±ÜÃâÎïÀí¼Ä´æÆ÷³åÍ»
c. R12ºÍR13¿ÉÄܱ»±àÒë ......
Cר¼Ò±à³Ì ¾«±àÖ®Ò» µÚÒ»ÕÂ~µÚÈýÕÂ
CµÄ¸´ÔÓÖ®´¦ ÔÚÓÚËüµÄÖ¸Õë ,µ«ÊDZÈÆäÖ¸Õë¸üΪ¸´ÔÓµÄÊÇËüµÄÉùÃ÷ !!!
ÄãÄÜ¿´¶®ËüÃǵÄÒâ˼ Âð?
apple=sizeof(int)*p ; apple=sizeof * p;
j= (char (*)[20])malloc(20);
int const * grape; Óë int * const gr ......
/*FIXME
ISO CÈç¹ûÄãÔÚmain()ÖÐд´úÂëµÄÖм䶨ÒåÁËÒ»¸ö¶ÔÓÚmain¶øÑÔµÄÈ«¾Ö±äÁ¿£¬¾Í»á±¨³öÕâ¸ö´íÎó¡£
*/
°ÑÕâ¸ö±äÁ¿¶¨Òåµ½mainº¯ÊýÖеÄ×îÇ°·½£¬¾Í»áÐÞÕýÕâ¸ö´íÎó¡£
¶øÇÒΪÁË·ÀÖ¹³ö´í£¬É趨µÄÖ¸ÕëÖ®ºóÔÙÓвÎÊý´«ÈëmallocÖ®ºóÁ¢¼´¶ÔÓÚÖ¸ÕëÓèÒÔ¿Õ¼äµÄ´´½¨¡£·ÀÖ¹³öÏÖÖ¸Õëδ³õʼ»¯´Ó¶øÒýÆð½«À´¸³ÖµµÄʱºò½«¸ÃÖµ¸²¸ÇÁËÒѾΪ±¾ ......