[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[Libevent-users] Multithreading -- bev release?
- To: libevent-users@xxxxxxxxxxxxx
- Subject: [Libevent-users] Multithreading -- bev release?
- From: Jan Danielsson <jan.m.danielsson@xxxxxxxxx>
- Date: Sun, 22 Apr 2012 06:24:15 +0200
- Delivered-to: archiver@xxxxxxxx
- Delivered-to: libevent-users-outgoing@xxxxxxxx
- Delivered-to: libevent-users@xxxxxxxx
- Delivery-date: Sun, 22 Apr 2012 00:24:28 -0400
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:organization:user-agent:mime-version:to :subject:x-enigmail-version:openpgp:content-type :content-transfer-encoding; bh=DcBvg85TKQSVn6yPsiLSiY8J4OQErT3WXbdE34JOs9M=; b=Is9/ijIGpzUL6CGWvkHUuYyU4kZXnWOY42sPW7mxYpJbm/iTVowzIFTCbFT4P+dHF7 zebv9/QIEoGPAGczXMf0YQgIBIgVlvifFnnRIzqklrczUpigBYzhTOoPRVDL6xlS3c1V 2knIVx/aQtnK8yTM4/tp1IOW/cayZr/S0U/dvKyKaARgqyL/Z2tINs0GXTWmcqE6jh6K CTnFNZMAyf5cRxxqtBQO/CrINIkoboAwjIeJYVSA0H5yzb0ErGANFAepJ7HwZTu2RjvM nAjrc6vrVpso8UUwci4x5mHqpHPmEeCeQPSUfsX/RKpSPf1hXiQMEjStV7ss0wAJ9Vsz 6QBw==
- Openpgp: id=13D7A8ED
- Organization: La Cosa Nostra
- Reply-to: libevent-users@xxxxxxxxxxxxx
- Sender: owner-libevent-users@xxxxxxxxxxxxx
- User-agent: Mozilla/5.0 (X11; NetBSD amd64; rv:8.0) Gecko/20111117 Thunderbird/8.0
Hello,
Say I do something along the line of:
--------------------------------
static void do_error(struct bufferevent *bev, short error, void *ctx)
{
int release = 0;
if(error & BEV_EVENT_EOF)
{
release = 1;
}
else if(error & BEV_EVENT_ERROR)
{
release = 1;
}
if(release)
{
parserctx_t *pctx = ctx;
/* ... */
free(pctx);
bufferevent_free(bev);
}
}
static void do_read(struct bufferevent *bev, void *ctx)
{
struct evbuffer *input;
parserctx_t *pctx = ctx;
/* ... */
input = bufferevent_get_input(bev);
/* ... */
if(got_complete_message)
{
launch_worker_thread(pctx);
}
/* ... */
}
void *worker_thread(parserctx_t *pctx)
{
struct bufferevent *bev = pctx->bev
struct evbuffer *output;
/* ... */
output = bufferevent_get_output(bev);
/* ... */
evbuffer_add_printf(output, "Results: %s", results);
/* ... */
}
--------------------------------
If the client closes the socket, do_error() will release bev, which -
I would assume - cause the worker_thread() to croak next time it
accesses bev/output.
There are a few solutions to this, the one I'm leaning towards is to
not release bev in do_error(), but rather flag it for deletion, and let
worker_thread() do it (if it has started; otherwise do_error() does it).
But it got me wondering if there are some mechanisms in libevent to
assist in these types of situations?
Are there any special caveats with releasing bev in a separate
thread? (Will it cause do_error() to be called on the base thread?).
--
Kind regards,
Jan Danielsson
***********************************************************************
To unsubscribe, send an e-mail to majordomo@xxxxxxxxxxxxx with
unsubscribe libevent-users in the body.