Groups | Search | Server Info | Keyboard shortcuts | Login | Register
Groups > comp.os.linux.development.system > #381
| From | Jorgen Grahn <grahn+nntp@snipabacken.se> |
|---|---|
| Newsgroups | comp.os.linux.development.system |
| Subject | Re: Calling libiptc API from a separate thread in a C program throws segmentati |
| Date | 2012-01-17 21:26 +0000 |
| Message-ID | <slrnjhbpr9.1ls.grahn+nntp@frailea.sa.invalid> (permalink) |
| References | <bKSdndZeXcWVzYjS4p2dnAA@giganews.com> <20120117102310.171@kylheku.com> |
On Tue, 2012-01-17, Kaz Kylheku wrote: > On 2012-01-17, kkgarg78 <nospam_kamalkgarg@gmail.com.invalid> wrote: >> I am working on performing iptables update through a custom c program using >> libiptc. >> >> The requirement is to invoke iptc APIs from a separate thread every 2 seconds. > > Even if there is no change to the rules? Are you monitoring for changes, > or updating? > >> The problem, I am facing is that call to both iptc_init() and iptc_free() >> works >> well when called from main function. However, call to iptc_free() fails with >> "Segmentation Fault" when called from thread_func(). > > I'm looing at the library sources online. It does not look thread-safe at all, > though it's not obvious how that could cause a crash in the above program, > since your use of the library is serialized (no concurrrency between > your main and thread_func). > > You should be fine if you have a dedicated thread which calls this > library, or put a big mutex around it. > >> Compilation: >> >> # gcc -o test thread_iptc.c -lpthread -lext4 -lext6 -lip4tc -lip6tc -liptc >> -lxtables -ldl > > This is not how you compile programs for multithreading. You want: > > # gcc -o test -pthread thread_iptc.c -lext4 -lext6 -lip4tc -lip6tc -liptc > -lxtables -ldl If he wants to be able to debug the crashes, he should also add -g, and also enable at least minimal compiler warnings. > I.e. the -pthread gcc option, not -lpthread. It is not enough to link the > threading library (and -pthread does that). > > One consequence of using -lpthread alone is that the "errno" variable will > not be properly thread-specific. > > At one point -pthread was equivalent to -D_REENTRANT and -lpthread, > but that may change in the future if it has not already; it's better > to use the -pthread interface. Either the gcc manual is incomplete, or your explanation is not entirely correct. For at least x86 and amd64, there is no -pthread option. It's there for ppc though. /Jorgen -- // Jorgen Grahn <grahn@ Oo o. . . \X/ snipabacken.se> O o .
Back to comp.os.linux.development.system | Previous | Next — Previous in thread | Next in thread | Find similar
Calling libiptc API from a separate thread in a C program throws segmentati kkgarg78 <nospam_kamalkgarg@gmail.com.invalid> - 2012-01-17 04:40 -0600
Re: Calling libiptc API from a separate thread in a C program throws segmentati Kaz Kylheku <kaz@kylheku.com> - 2012-01-17 18:48 +0000
Re: Calling libiptc API from a separate thread in a C program throws segmentati Jorgen Grahn <grahn+nntp@snipabacken.se> - 2012-01-17 21:26 +0000
Re: Calling libiptc API from a separate thread in a C program throws segmentati Kaz Kylheku <kaz@kylheku.com> - 2012-01-17 22:03 +0000
Re: Calling libiptc API from a separate thread in a C program throws segmentati Richard Kettlewell <rjk@greenend.org.uk> - 2012-01-17 22:07 +0000
Re: Calling libiptc API from a separate thread in a C program throws segmentati Kaz Kylheku <kaz@kylheku.com> - 2012-01-17 22:34 +0000
Re: Calling libiptc API from a separate thread in a C program throws segmentati Richard Kettlewell <rjk@greenend.org.uk> - 2012-01-17 22:51 +0000
Re: Calling libiptc API from a separate thread in a C program throws segmentati Kaz Kylheku <kaz@kylheku.com> - 2012-01-17 23:13 +0000
Re: Calling libiptc API from a separate thread in a C program throws segmentati Jorgen Grahn <grahn+nntp@snipabacken.se> - 2012-01-17 22:56 +0000
Re: Calling libiptc API from a separate thread in a C program throws segmentati Richard Kettlewell <rjk@greenend.org.uk> - 2012-01-21 11:29 +0000
csiph-web