Code Monkey home page Code Monkey logo

Comments (5)

azat avatar azat commented on June 16, 2024 1

Take a look at event_use_pthreads and BEV_OPT_THREADSAFE.

from libevent.

Xuzhangxin avatar Xuzhangxin commented on June 16, 2024

please

from libevent.

Xuzhangxin avatar Xuzhangxin commented on June 16, 2024

Thank you for your answer. I have added what you said, but it doesn't seem to meet my needs. My code is like this:
bufferevent *buffEvent = bufferevent_socket_new...
....
m_buffEvent = buffEvent

When I need to send data, I directly use bufferevent_write(m_buffEvent, data, dataLen) in another thread to actively send data to the client. Assume that in the thread of event_base_dispatch, errnocb is called, and bufferevent_free is called, reference counting When it is 0, the memory is released, and at this time, m_buffEvent is accessed in another thread.

It seems like what you said doesn't work in this case?

from libevent.

azat avatar azat commented on June 16, 2024

After calling bufferevent_free you should not use the bufferevent, it is your responsibility.

I would recommend you to wrap bufferent * into shared_ptr with custom deleter as bufferevent_free and this will work like a charm.

from libevent.

Xuzhangxin avatar Xuzhangxin commented on June 16, 2024

okay, thank you very much. I understand what you mean!

from libevent.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.