linuxÏß³Ì(pthread)±à³ÌÖеÄsegmentation fault£¡£¡
linuxÏß³Ì(pthread)±à³ÌÖеÄsegmentation fault£¡£¡
Posted on ÐÇÆÚÎå, 3ÔÂ 27th, 2009 at 10:28 ÏÂÎç
Ô´ÎÄÀ´×Ôhttp://www.isongzi.com/2009/03/27/pthread-segmentation-fault/
¼Ìsocket bad addres ´íÎóÖ®ºó£¬ÔÚ´´½¨Ï̡߳¾pthread_create()¡¿µÄʱºòÓÖ³öÏÖÁË segmentation fault¡£
´íÎóÓï¾äÈçÏ£º
pthread_create(&dec_tid,NULL, (void *)&encode, (void *)&cmd);
encode ÉùÃ÷ÈçÏ£º
int encode(void *arg);
¿ªÊ¼ÎÒÏëµÄÊÇ£¬»á²»»áÊÇencodeÇ°Ãæ²»ÓüÓ&ÄØ£¿°´ÕÕÉùÃ÷¶¨Ò壺
pthread_create(&tid, &attr, (void *)myfunction, myarg);
µÚÈý¸ö²ÎÊý¾ÍÊǺ¯ÊýÃû¶øÒÑ£¬ÊÇΪÁ˱íÃ÷Ï̺߳¯ÊýµÄÈë¿ÚµØÖ·¡£µ«ÊÇ£¬¿´µÄfreescaleÌṩµÄ²Î¿¼³ÌÐòÖÐÓÐÔ´ÂëÊÇÕâÑùµÄ£º
pthread_create(&sigtid, NULL, (void *)&signal_thread, NULL);
Ò²¾ÍÊÇ˵£¬¿ÉÒ԰ѵÚÈý¸ö²ÎÊýÒ²¼´º¯ÊýÃûÇ°Ãæ¼ÓÉÏ&£¬Á½¸öЧ¹ûÒ»Ñù¡£ÎªÁ˼ìÑéµ½µ×ʲôµØ·½´íÎ󣬻¹ÊǸÄÁËһϣº
pthread_create(&dec_tid,NULL, (void *)encode, (void *)&cmd);
°ÑencodeÇ°Ãæ µÄ&È¥µô£¬µ«ÊÇÒÀÈ»segmentation fault.¡£
ÍøÉÏÕÒÁËһϣ¬ÔÒòÔÚÓÚµ÷ÊÔµÄʱºòû¼Ó -lpthread!ÏëÒª±àÒë¶àÏ̵߳ijÌÐò£¬±ØÐëÈçϱàÒ룺
gcc -o test -lpthread test.c£¬
ÒòΪÏ߳̿ⲻÊÇÄÚºË×Ô´øµÄ£¬ÒªÏÔʽ˵Ã÷¡£ÎÊÌâÊÇ£¬ÎªÊ²Ã´GCCÔÚ±àÒëµÄʱºò²»±¨´íÄØ£¿
Õâ¸öÎÊÌâ±È½ÏÓÐÄѶȡ£ºÃÁË£¬ÔÒòÕÒµ½ÁË£¬Ôõô½â¾ö£¿Makefile ÎļþÈçÏ£º
#This Makefile is from http://isongzi.com which is to make send.out
CC=$(CROSS_COMPILE)gcc
LINK=$(CROSS_COMPILE)gcc
CROSS_COMPILE=arm-926ejs-linux-
OBJ = main.o \
enc.o \
capture.o \
fb.o \
socket.o \
OBJDIR=./bin
LIBNAME = libvpu.a
LIBDIR = ./lib/
# list of platforms which want this test case
INCLUDE_LIST:=IMX27ADS IMX31ADS MXC30031ADS IMX27MDK27V0
TARGET = send.out
all: $(TARGET) $(TARGET1)
$(TARGET): $(LIBDIR)$(LIBNAME) $(OBJ)
$(LINK) -L . -lpthread -o $(TARGET) $(OBJ) $(LIBNAME)
mkdir -p $(OBJDIR)
mv $(TARGET) $(OBJDIR)
mv $(LIBNAME) $(OBJDIR)
%.o: %.c
$(CC) -Wall -O2 -I $(LIBDIR) -c $^ -o $@
$(LIBDIR)$(LIBNAME):
make -C $(LIBDIR)
mv $(LIBDIR)$(LIBNAME) .
.PHONY: clean
clean:
rm -f $(OBJDIR)/$(TARGET) $(OBJ) $(LIBNAME)
ÔÀ´
Ïà¹ØÎĵµ£º
£¨L2CAPÐÒé¼ò½é£¬L2CAPÔÚBlueZÖеÄʵÏÖÒÔ¼°L2CAP±à³Ì½Ó¿Ú£©
Ò»£ºL2CAPÐÒé¼ò½é£º
Logical Link Control and Adaptation Protocol(L2CAP)
Âß¼Á¬½Ó¿ØÖƺÍÊÊÅäÐÒé (L2CAP) ΪÉϲãÐÒéÌṩÃæÏòÁ¬½ÓºÍÎÞÁ¬½ÓµÄÊý¾Ý·þÎñ£¬²¢Ìṩ¶àÐÒ鹦ÄܺͷָîÖØ×é²Ù×÷¡£L2CAP ³äÐíÉϲãÐÒéºÍÓ¦ÓÃÈí¼þ´«ÊäºÍ½ÓÊÕ×î´ó³¤¶ÈΪ 64K µÄ L2CAP Ê ......
Service Discovery Protocol(SDP)ÌṩһÖÖÄÜÁ¦£¬ÈÃÓ¦ÓóÌÐòÓз½·¨·¢ÏÖÄÄÖÖ·þÎñ¿ÉÓÃÒÔ¼°ÕâÖÖ·þÎñµÄÌØÐÔ¡£
·þÎñ·¢ÏÖÐÒé(SDP»òBluetooth SDP)ÔÚÀ¶ÑÀÐÒéÕ»ÖжÔÀ¶ÑÀ»·¾³ÖеÄÓ¦ÓóÌÐòÓÐÌØÊâµÄº¬Ò⣬·¢ÏÖÄĸö·þÎñÊÇ¿ÉÓõĺÍÈ·¶¨ÕâЩ¿ÉÓ÷þÎñµÄÌØÕ÷¡£SDP¶¨ÒåÁËbluetooth client·¢ÏÖ¿ÉÓÃbluetooth server·þÎñºÍËüÃǵÄÌØÕ÷µÄ·½·¨¡£ ......
ÐÞ¸Ä linux ϵͳ/ect/profile Îļþ
ÔÚ×îºóÃæ¼Ó
export LC_ALL="zh_CN.GB18030"
ÐÞ¸Ä /etc/sysconfig/i18nÎļþ
LANG="zh_CN.GB18030"
LANGUAGE="zh_CN.GB18030:zh_CN.GB2312:zh_CN"
SUPPORTED="zh_CN.GB18030:zh_CN:zh:en_US.UTF-8:en_US:en"
SYSFONT="lat0-sun16"
SYSFONTACM="iso01"
ÕâÑù¾Í¿ÉÒÔ½â¾ölinuxÏÂÖÐÎÄ ......
ÕâôÄã¾ÍÐèÒªÐÞ¸ÄÒ»ÏÂ×Ö·û±àÂëµÄÅäÖá£
# cd /etc/sysconfig
# vi i18n
-------------------ÎļþÄÚÈÝ------------------
LANG="zh_CN.GB18030"
SUPPORTED="zh_CN.UTF-8:zh_CN:zh:en_US.UTF-8:en_US:en:zh_CN.GB18030"
SYSFONT="latarcyrheb-sun16"
-----------------------£ºqw ±£´æÍ ......
ÕªÒª: ±¾ÎÄÏê½âÁËÄÚºËÖÐÃæÏò¶ÔÏóµÄlist½á¹¹µÄÔÀí£¬ÒÔ¼°ÈçºÎÒÔlistΪÄÚǶ¶ÔÏóÀ´¹¹Ôì×Ô¼ºµÄÁ´±í½á¹¹£¬ÈçºÎ´ÓÄÚǶlist¶ÔÏó»ñµÃ×Ô¶¨ÒåµÄ¶ÔÏóÖ¸Õ룻̽ÌÖÁ˸÷ÖÖºê»òÕߺ¯ÊýµÄÏêϸʹÓ÷½·¨¼°ÔõÑùÒÔͨÓÃlist½á¹¹À´²Ù×÷×Ô¶¨Òå¶ÔÏó¡£
¹Ø¼ü×Ö:Ë«ÏòÑ»·Á´±í£¬list£¬list_entry£¬typeof£¬containerof£¬list_for_each,list_for_each ......