Boost like libraries in C [closed] - c

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 6 years ago.
Improve this question
Can you recommend peer reviewed libraries that I can use in C environment (something like Boost for C++) ? Something that provides hash, thread, interprocess communications, lists, smart memory management...
The environment is embedded system, not a very minimal system, but also not a PC!

+1 for GLib from me, too. Plus, it has its own threading API too, so you don't have to learn pthreads if you don't want to.
Not sure if there exists such a thing as "smart memory management" in C, it's not very easy when you don't have the safety nets of destructors and control over operators. But, again, GLib has plenty of memory-oriented data structures and stuff that really makes life easier.
And no, I'm not on the GLib team, but I really do like it. :)

Check out the Apache Portable Runtime (APR) project.
Some of it's features:
memory management API
threads, mutexes
file I/O
atomic operations
hash tables, arrays
network sockets and protocol
shared memory, mmap
Not to mention it's portable.

I'm not sure if you'll find a single library that covers all of that... but you can check out glib and pthreads to cover a good bit of that.

Look at Boehm GC a widely used conservative garbage collector for C (or C++) that might serve your needs as far as smart memory management is concerned.

I'll jump on the GLib bandwagon too. Remember that C doesn't provide any syntactic sugar for complex data structures, so there are lots of casts and long function names in GLib, but it really does a great and efficient job with a little added verbosity!!

About the Glib use.
You probably can take what you need and cross-compile it. So if you just need the thread package - just compile that and don't take everything.
I'm doing the same thing with the Python VM. PyMite fits on a microcontroller and doesn't use all the functionality.

Related

Windows programmer moving to linux - Coding conventions [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I have been developing for Windows for a long time, mainly WinApi (and .Net).
I'v started learning basic Linux, and I have some questions regarding the differences:
In Windows I have barely used the C Standard library.
If I needed an API, I would search MSDN and find the appropriate library\function.
From what it seems like, in Linux the C Standard library is EVERYTHING.
All the code samples I have seen used the standard library (Instead of using some Linux internal functions, like a Linux "CreateFile").
Is this really how writing "proper" linux code is done ? Using the C standard library ?
If I wish to read a file, or allocate memory are fopen\malloc the way to go ?
If the answer to my first question is yes (And I guess it will be)
The C standard library is POWERLESS compared to the powerful WinApi.
Lets say I wish to get a list of running process (CreateToolhelp32Snapshot) or create a thread or a process (CreateThread\CreateProcess), How should I do that in Linux ?
Documentation.
In Windows, all I need can be found in MSDN.
If I have a "how do I do" question (Like the questions above) where should I go ?
Where is my main source of documentation.
Thanks a lot,
Michael.
Perhaps you've forgotten that the Standard C Library isn't environment-specific, it specifies least-common-denominator functionality among all systems that can run C programs, and C runs on systems that don't even have processes.
If you want an API that provides consistent common GUI/multithread/etc. APIs, pick a likely-looking GUI/multithread/etc. API. You might start with Qt, it's quite comprehensive and produces good-looking, near-native UIs on a host of systems.
It's not generally considered polite to point this out, but most questions that get asked publicly are asked by people who lack the discipline to do even simple research. Once people can do that, they don't need to ask very many, and that's why what you see is so ... trivial. You're past that. For more options, you could start here.
For more general-purpose tools, the top hit on a search for important linux tools might be helpful.

Modern Ada to C/C++ translator [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
Improve this question
Is there any source-to-source converter (translator) from Ada (95, 2005) to C?
How full they are (can they convert every feature of Ada into gnu c99 + pthreads + POSIX)?
Is it possible to use such ada-to-c translator in critical applications?
PS: Translators to C++ (up to 2003 with gnu extensions) are welcome too.
PPS: when said "gnu c99", it means only that C99 + most gnu extensions are supported, but don't mean the GCC.
I don't know of any open source Ada-to-C translator. The only one I knew of at all was SofCheck's, which was reportedly pretty good.
SofCheck has since been bought by AdaCore, and I did a very brief search of the AdaCore website for the translator, and nothing jumped out. You could ask them at sales#adacore.com, if pursuing a commercial solution is a viable option for you. (At least get a price.)
Unless there is an incredibly strong reason to use Ada for this application (e.g., customer demands it, or you already have a big application coded in Ada that you want to use), it will likely be a lot less painful if you just bite the bullet and code your solution in well-crafted C99 or C++ as you see fit.
If you insist, Sofcheck's translator might be best; they've been working on it a long time.
Failing that, you might(?) build a translator starting with the ASIS output of an Ada compiler. That's likely rather a lot of persnickety work since Ada has pretty precise semantics that you'd better preserve if you want to just carelessly code in Ada, translate and run. It will be even more work if you want the output to be "pretty" for the final customer. (Long term maintenance should be a consideration). I suspect implementing code to simulate Ada's rendezvous might be rather tricky, being both semantically complicated and asynchronous at the same time. The real flaw with this approach is that it is a lot of work; maybe just getting on with your life and coding the application itself in something non-Ada would be less effort.
See my caveats on language translation done poorly and alternative methods.

Existing threadpool C implementation [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
Improve this question
What open-source implementation(s) in C for a pthreads thread pool would you recommend ?
Additional points if this implementation is :
Light-weight: glib, APR, NSPR and others come with a big buy-in, I'd rather have just 2 files (header and implementation).
Tested on several platforms (Linux, BSD, Mac OS X, etc.).
Still maintained.
I worked on making something I'd be able to use and I've published it on github: it's unimaginably called threadpool.
If your goal is light-weight, then the last thing you want is a prewritten, super-general-purpose, high-level-abstraction-based implementation. Implementing a thread pool yourself, suited to your particular task, is fairly trivial, but you might also question whether you actually need a thread pool or whether you'd be fine just creating and destroying threads as needed.
Without knowing more details about your application, I can't give much more specific advice. But the tools you might find useful are:
Condition variables
Semaphores
A job queue protected by a mutex
POSIX message queues
Here is an implementation with these features:
ANSI C and POSIX compliant
Minimal but powerful API
Synchronisation from the user
Full documentation
I once used this, which isn't actually an official implementation per se. It does use pthreads as you requested, and should give you some ideas of what you need to do. (See threadpool.h, threadpool.c, threadpool_test.c, and the Makefile for instructions on how to compile.) You'll obviously have to do some refactoring as it's original intention is probably different than yours. It's commented rather well actually.
Even though this deviates from the original question, I'd also like to mention that the newest C standard, unofficially C1X (see wikipedia, hyperlink limit), has planned support for threads N1570 (google it, hyperlink limit again!) (7.31.15).
Some personal advice from my experience would be to make sure that your application can actually be run in parallel, and if the overhead of creating a new thread is so high that you can't live without a thread pool. Personally I've blundered on both these parts and I've actually ended up with implementations slower than my single threaded application. Also, you might want to be aware of different problems, including cache-lockouts and misses, which would actually degrade the performance of your application.
I'm probably blabbering on by now, but best of luck.

Simple/canonical implementations of synchronization primitives? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
Improve this question
I'm looking for a good online reference on typical implementation of synchronization primitives (spinlocks, mutexes, semaphores, read-write locks, conditional variables, ...) either in abstract c+atomics or pseudo-asm (i.e. any reasonable notation of the sequence of atomic operations performed) or x86 asm. Something that starts with the most naive implementations and then addresses their shortcomings and some of the approaches to solving the shortcomings would be great.
Try Tanenbaum's Operating Systems: Design and Implementation.
edit: or Modern Operating Systems. I think the 1st one includes Minix, the 2nd one doesn't. Not sure, sorry =(
It's academically oriented, so it'll get you started on the right path.
Not a complete reference by any means, but the following paper is a classic and essential for understanding the implementation of synchronisation primitives in Linux:
"Fuss, Futexes and Furwocks: Fast Userlevel locking in Linux", Franke Russell & Kirkwod, Proceedings of the Ottawa Linux Symposium 2002 - available (among others) at: http://www.cis.temple.edu/~ingargio/cis307/readings/futex0.pdf
From that and the glibc sources it's possible to learn a lot, but it's not what I'd call easy-going :-)
As a side note, if you just want atomic stuff and you'r using gcc you have some built in functions that you can use instead of asm.
http://gcc.gnu.org/onlinedocs/gcc-4.1.2/gcc/Atomic-Builtins.html
But for specific locks you always have Wikipedia
http://en.wikipedia.org/wiki/Spinlock
http://en.wikipedia.org/wiki/Semaphore_(programming)
Also worth looking at is
http://en.wikipedia.org/wiki/Lock-free_and_wait-free_algorithms

Mature standard library for C [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a book, tool, software library, tutorial or other off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 8 years ago.
Improve this question
I'm looking for a library for C that gives me at least some of the things I really miss from C++ and the STL/Boost. (I have to use C, so please no "use C++" posts)
I need
dynamic strings (that grow and shrink automatically)
some sort of list (std::vector replacement)
something like stringstream (for type conversations & buffers)
Furthermore, it has to have a mature and Open Source implementation and it has to be platform independant (Windows, Linux and Mac are required to be supported).
Any recommendations?
What about the GLib from GTK?
I'd recommend the Apache Portable Runtime. It's reasonably small, portable, and powerful - powers the Apache httpd across multiple platforms, at least.
You could always consider embedding a dynamic language runtime in your application. The Lua core is not large at all, provides data types that meet your requirements, is open source, and MIT licensed so it is compatible with both FOSS and commercial projects.
You wouldn't necessarily need to use code written in Lua to benefit, as its C API provides complete access to its data types and their values. However, you could later move some of the logic of your application into Lua, for the improved clarity of expression and other benefits of coding in a dynamic language with functions as first-class values.
Take a look at Gnulib

Resources