[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[Libevent-users] Re: libevent 2.0.4: Segmentation fault with BEV_OPT_THREADSAFE set



Nerver mind. it's my fault.

It need to include event2/thread.h and links event_pthreads to make it run

On Fri, Apr 2, 2010 at 5:53 PM, Jarod Liu <liuyuanzhi@xxxxxxxxx> wrote:
> My demo code works fine without the BEV_OPT_THREADSAFE option.
> With the option segmentation fault  100% will happen.
>
> Maybe it is a platform specified problem, I see no one report before.
>
> =====================================================================
> $ /usr/bin/c++ --version
> c++ (GCC) 4.1.2 20080704 (Red Hat 4.1.2-46)
>
> $ lsb_release -a
> LSB Version:
> :core-3.1-ia32:core-3.1-noarch:graphics-3.1-ia32:graphics-3.1-noarch
> Distributor ID: CentOS
> Description:    CentOS release 5.4 (Final)
> Release:        5.4
> Codename:       Final
>
> =====================================================================
> *** Aborted at 1270200692 (unix time) try "date -d @1270200692" if you
> are using GNU date ***
> PC: @   0x17637a _bufferevent_incref_and_lock
> *** SIGSEGV (@0x100) received by PID 32210 (TID 0xb7f8e6d0) from PID
> 256; stack trace: ***
>    @   0x499440 (unknown)
>    @   0x176d5c bufferevent_enable
>    @  0x804901e accept_conn_cb()
>    @   0x179d23 listener_read_cb
>    @   0x16e5a9 event_base_loop
>    @   0x16f1a5 event_base_dispatch
>    @  0x8048f4d main
>    @   0xa99e9c (unknown)
>    @  0x8048b21 (unknown)
> Segmentation fault
>
> =====================================================================
> #include <cstring>
> #include <event2/util.h>
> #include <event2/event.h>
> #include <event2/bufferevent.h>
> #include <event2/listener.h>
>
> static void accept_conn_cb(struct evconnlistener* listener,
>    evutil_socket_t sockfd, struct sockaddr* addr, int socklen,
>    void *user_data) {
>
>  struct event_base *base = evconnlistener_get_base(listener);
>  struct bufferevent *bev = bufferevent_socket_new(
>                        base,  sockfd,  BEV_OPT_CLOSE_ON_FREE |
> BEV_OPT_THREADSAFE);
>  bufferevent_enable(bev,  EV_READ | EV_WRITE);
>
>  for (char i='a'; i<'z'; i++) {
>    bufferevent_write(bev, &i, sizeof(i));
>  }
> }
>
> int main(int argc, char** argv) {
>  struct event_base *base;
>  struct sockaddr_in sin;
>  struct evconnlistener *listener;
>
>  base = event_base_new();
>
>  memset(&sin,  0,  sizeof(sin));
>  sin.sin_family = AF_INET;
>  sin.sin_addr.s_addr = htonl(0);
>  sin.sin_port = htons(9050);
>
>  listener = evconnlistener_new_bind(base,  accept_conn_cb,  NULL,
>                    LEV_OPT_CLOSE_ON_FREE|LEV_OPT_REUSEABLE,  SOMAXCONN,
>                                        (struct sockaddr*)&sin,  sizeof(sin));
>  event_base_dispatch(base);
>  return 0;
> }       // ----------  end of function main  ----------
>
***********************************************************************
To unsubscribe, send an e-mail to majordomo@xxxxxxxxxxxxx with
unsubscribe libevent-users    in the body.