Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

LinuxÏÂthread±à³Ì£¨¶þ£©

×÷Õߣº Sam£¨Õç·å£© sam_code@hotmail.com
threadÊôÐÔ£º
pthread_create()ÖУ¬µÚ¶þ¸ö²ÎÊý£¨pthread_attr_t£©Îª½«Òª´´½¨µÄthreadÊôÐÔ¡£Í¨³£Çé¿öÏÂÅäÖÃΪNULL£¬Ê¹ÓÃȱʡÉèÖþͿÉÒÔÁË¡£
µ«Á˽âÕâЩÊôÐÔ£¬ÓÐÀûÓÚ¸üºÃµÄÀí½âthread.
ÊôÐÔ¶ÔÏó£¨pthread_attr_t£©ÊDz»Í¸Ã÷µÄ£¬¶øÇÒ²»ÄÜͨ¹ý¸³ÖµÖ±½Ó½øÐÐÐ޸ġ£ÏµÍ³ÌṩÁËÒ»×麯Êý£¬ÓÃÓÚ³õʼ»¯¡¢ÅäÖúÍÏú»ÙÿÖÖ¶ÔÏóÀàÐÍ¡£
´´½¨ÊôÐÔ£º
int pthread_attr_init(pthread_attr_t *attr);
´´½¨µÄÊôÐÔÉ趨ΪȱʡÉèÖá£
Ïú»ÙÊôÐÔ£º
int pthread_attr_destroy(pthread_attr_t *attr);
Ò»£ºÉèÖ÷ÖÀë״̬£º
Ï̵߳ķÖÀë״̬ÓÐ2ÖÖ£ºPTHREAD_CREATE_JOINABLE£¨·Ç·ÖÀë״̬£©£¬ PTHREAD_CREATE_DETACHED£¨·ÖÀë״̬£©
·ÖÀë״̬º¬ÒåÈçÏ£º
Èç¹ûʹÓà PTHREAD_CREATE_JOINABLE ´´½¨·Ç·ÖÀëỊ̈߳¬Ôò¼ÙÉèÓ¦ÓóÌÐò½«µÈ´ýÏß³ÌÍê³É¡£Ò²¾ÍÊÇ˵£¬³ÌÐò½«¶ÔÏß³ÌÖ´ÐÐ pthread_join¡£ ·Ç·ÖÀëÏß³ÌÔÚÖÕÖ¹ºó£¬±ØÐëÒªÓÐÒ»¸öÏß³ÌÓà join À´µÈ´ýËü¡£·ñÔò£¬²»»áÊͷŸÃÏ̵߳Ä×ÊÔ´ÒÔ¹©ÐÂÏß³ÌʹÓ㬶øÕâͨ³£»áµ¼ÖÂÄÚ´æй©¡£Òò´Ë£¬Èç¹û²»Ï£ÍûÏ̱߳»µÈ´ý£¬Ç뽫¸ÃÏß³Ì×÷Ϊ·ÖÀëÏß³ÌÀ´´´½¨¡£
Èç¹ûʹÓà PTHREAD_CREATE_DETACHED ´´½¨·ÖÀëthread,Ôò±íÃ÷´ËthreadÔÚÍ˳öʱ»á×Ô¶¯»ØÊÕ×ÊÔ´ºÍthread ID.
Sam֮ǰºÜϲ»¶Ê¹Ó÷ÖÀëthread. µ«ÏÖÔÚÂýÂýʹÓÃÖоõµÃÕâÑùÊǸö²»ºÃµÄÏ°¹ß¡£ÒòΪ·ÖÀëthreadÓиöÎÊÌ⣺Ö÷³ÌÐòÍ˳öʱ£¬ºÜÄÑÈ·ÈÏ×ÓthreadÒѾ­Í˳ö¡£Ö»ºÃʹÓÃÈ«¾Ö±äÁ¿À´±êÃ÷×ÓthreadÒѾ­Õý³£Í˳öÁË¡£
ÁíÍ⣺²»¹Ü´´½¨·ÖÀ뻹ÊÇ·Ç·ÖÀëµÄthread.ÔÚ×ÓthreadÈ«²¿Í˳ö֮ǰÍ˳öÖ÷³ÌÐò¶¼ÊǺÜÓзçÏյġ£Èç¹ûÖ÷thread Ñ¡Ôñreturn,»òÕßµ÷ÓÃexit()Í˳ö£¬ÔòËùÓÐthread¶¼»á±»killµô¡£ÕâÑùºÜÈÝÒ׳ö´í¡£SamÉϴγöµÄÎÊÌâÆäʵ¾ÍÊÇÕâ¸ö¡£µ«Èç¹ûÖ÷threadÖ»Êǵ÷ÓÃpthread_exit().Ôò½öÖ÷Ï̱߳¾ÉíÖÕÖ¹¡£½ø³Ì¼°½ø³ÌÄÚµÄÆäËûÏ߳̽«¼ÌÐø´æÔÚ¡£ËùÓÐÏ̶߳¼ÒÑÖÕֹʱ£¬½ø³ÌÒ²½«ÖÕÖ¹¡£
int pthread_attr_getdetachstate(const pthread_attr_t *attr,int *detachstate);
int pthread_attr_setdetachstate(pthread_attr_t *attr, int detachstate);
µÃµ½µ±Ç°ºÍ·ÖÀë״̬ºÍÉèÖõ±Ç°µÄ·ÖÀë״̬¡£
¶þ£ºÉèÖÃÕ»Òç³ö±£»¤Çø´óС:
Õ»Òç³ö¸ÅÄ
Òç³ö±£»¤¿ÉÄܻᵼÖÂϵͳ×ÊÔ´ÀË·Ñ¡£Èç¹ûÓ¦ÓóÌÐò´´½¨´óÁ¿Ị̈߳¬²¢ÇÒÒÑÖªÕâЩÏß³ÌÓÀÔ¶²»»áÒç³öÆäÕ»£¬Ôò¿ÉÒԹرÕÒç³ö±£»¤Çø¡£Í¨¹ý¹Ø±ÕÒç³ö±£»¤Çø£¬¿ÉÒÔ½Úʡϵͳ×ÊÔ´¡£
Ïß³ÌÔÚÕ»ÉÏ·ÖÅä´óÐÍÊý¾Ý½á¹¹Ê±£¬¿ÉÄÜÐèÒª½Ï´óµÄÒç³ö±£»¤ÇøÀ´¼ì²âÕ»Òç³ö¡£
int pthre


Ïà¹ØÎĵµ£º

ʵսLinux Bluetooth±à³Ì (Æß) SDPЭÒé

Service Discovery Protocol(SDP)ÌṩһÖÖÄÜÁ¦£¬ÈÃÓ¦ÓóÌÐòÓз½·¨·¢ÏÖÄÄÖÖ·þÎñ¿ÉÓÃÒÔ¼°ÕâÖÖ·þÎñµÄÌØÐÔ¡£
·þÎñ·¢ÏÖЭÒé(SDP»òBluetooth SDP)ÔÚÀ¶ÑÀЭÒéÕ»ÖжÔÀ¶ÑÀ»·¾³ÖеÄÓ¦ÓóÌÐòÓÐÌØÊâµÄº¬Ò⣬·¢ÏÖÄĸö·þÎñÊÇ¿ÉÓõĺÍÈ·¶¨ÕâЩ¿ÉÓ÷þÎñµÄÌØÕ÷¡£SDP¶¨ÒåÁËbluetooth client·¢ÏÖ¿ÉÓÃbluetooth server·þÎñºÍËüÃǵÄÌØÕ÷µÄ·½·¨¡£ ......

LinuxÍü¼ÇÁËrootµÄÃÜÂëµÄ½â¾ö°ì·¨

1. ϵͳÆô¶¯ºó,ÔÚ³öÏÖgrub»­Ãæʱ£¬ÓÃÉÏϼüÑ¡ÖÐÄãƽʱÆô¶¯linuxµÄÄÇÒ»ÏȻºó°´e¼ü
2. ÔÙ´ÎÓÃÉÏϼüÑ¡ÖÐÄãƽʱÆô¶¯linuxµÄÄÇÒ»Ïî(ÀàËÆÓÚkernel/boot mlinuz-2.4.18-14 ro root=LABEL=/)£¬È»ºó°´e¼ü
3. ÐÞ¸ÄÄãÏÖÔÚ¼ûµ½µÄÃüÁîÐУ¬¼ÓÈësingle£¬½á¹ûÈçÏ£º
    kernel /boot mlinuz-2.4.18-14 single ro ......

linux¿âÎļþ±àдÈëÃÅ¡¾Õª×Ô chinaunix¡¿

תÌù×Ô: http://hi.baidu.com/harrybobo/blog/item/ae3347b51711afc637d3ca69.html
Ò»¡¢ÎªÊ²Ã´ÒªÊ¹ÓÿâÎļþ
ÎÒÃÇÔÚʵ¼Ê±à³Ì¹¤×÷Öп϶¨»áÓöµ½ÕâÖÖÇé¿ö£ºÓм¸¸öÏîÄ¿ÀïÓÐһЩº¯ÊýÄ£¿éµÄ¹¦ÄÜÏàͬ£¬
ʵÏÖ´úÂëÒ²Ïàͬ£¬Ò²ÊÇÎÒÃÇËù˵µÄÖظ´´úÂë¡£±ÈÈ磬ºÜ¶àÏîÄ¿ÀﶼÓÐÒ»¸öÓû§ÑéÖ¤µÄ¹¦ÄÜ¡£
´úÂë¶ÎÈçÏ£º
//UserLogin.hÎļþ£¬Ìá ......

³ÌÐòµÄÁ´½ÓºÍ×°Èë¼°Linux϶¯Ì¬Á´½ÓµÄʵÏÖ ÊÕ²Ø

  ¼¶±ð£º ³õ¼¶ ÍõÓ (yongwang@buaa.edu.cn), ±±¾©º½¿Õº½Ìì´óѧ¼ÆËã»úѧԺϵͳÈí¼þʵÑéÊÒ 2003 Äê 8 Ô 10 ÈÕ ³ÌÐòµÄÁ´½ÓºÍ×°Èë´æÔÚ×ŶàÖÖ·½·¨£¬¶øÈç½ñ×îΪÁ÷Ðеĵ±Êô¶¯Ì¬Á´½Ó¡¢¶¯Ì¬×°Èë·½·¨¡£±¾ÎÄÊ×ÏȻعËÁËÁ´½ÓÆ÷ºÍ×°ÈëÆ÷µÄ»ù±¾¹¤×÷Ô­Àí¼°ÕâÒ»¼¼ÊõµÄ·¢Õ¹ÀúÊ·£¬È»ºóͨ¹ýʵ¼ÊµÄÀý×ÓÆÊÎöÁËLinuxϵͳ϶¯Ì¬Á´½ÓµÄÊµÏ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ