Quantcast
Channel: How to "multithread" C code - Stack Overflow
Browsing all 14 articles
Browse latest View live

Answer by Antonin GAVREL for How to "multithread" C code

I think all the answers lack a concrete example with implementation of threads across different function, passing parameters and some benchmarks:// NB: gcc -O3 pthread.c -lpthread && time...

View Article



Answer by Ciro Santilli OurBigBook.com for How to "multithread" C code

C11 threads in glibc 2.28.Tested in Ubuntu 18.04 (glibc 2.27) by compiling glibc from source: Multiple glibc libraries on a single hostExample from:...

View Article

Answer by Mohd Shibli for How to "multithread" C code

You can use pthreads to perform multithreading in C.here is a simple example based on pthreads.#include <pthread.h>#include <stdio.h>void *mythread1(); //thread prototypevoid...

View Article

Answer by darklon for How to "multithread" C code

Intel's C++ compiler is actually capable of automatically paralellizing your code. It's just a compiler switch you need to enable. It doesn't work as well as OpenMP though (ie. it doesn't always...

View Article

Answer by ifyes for How to "multithread" C code

If an iteration in loop is independent of the ones before it, then there's a very simple approach: try multi-processing, rather than multi-threading. Say you have 2 cores and ntimes is 100, then...

View Article


Answer by Mecki for How to "multithread" C code

Your code is not automatically multi-threaded by the compiler if that was your question. Please note that the C standards themselves know nothing about multi-threading, since whether you can use...

View Article

Answer by AlcubierreDrive for How to "multithread" C code

To specifically address the "automatically multithreaded" part of the OP's question:One really interesting view of how to program parallelism was designed into a language called Cilk Plus invented by...

View Article

Answer by user191776 for How to "multithread" C code

One alternative to multithread your code would be using pthreads ( provides more precise control than OpenMP ).Assuming x, y& result are global variable arrays,#include <pthread.h>...void...

View Article


Answer by Marcin for How to "multithread" C code

a good exercise for learning concurrent programming in any language would be to work on a thread pool implementation.In this pattern you create some threads in advance. Those threads are treated as an...

View Article


Answer by nategoose for How to "multithread" C code

You should have a look at openMP for this. The C/C++ example on this page is similar to your code:https://computing.llnl.gov/tutorials/openMP/#SECTIONS#include <omp.h>#define N 1000main (){int...

View Article

Answer by asveikau for How to "multithread" C code

If you are hoping to provide concurrency for a single loop for some kind of scientific computing or similar, OpenMP as @Novikov says really is your best bet; this is what it was designed for.If you're...

View Article

Answer by ValiRossi for How to "multithread" C code

Depending on the OS, you could use posix threads. You could instead implement stack-less multithreading using state machines. There is a really good book entitled "embedded multitasking" by Keith E....

View Article

Answer by Novikov for How to "multithread" C code

If the task is highly parallelizable and your compiler is modern, you could try OpenMP. http://en.wikipedia.org/wiki/OpenMP

View Article


How to "multithread" C code

I have a number crunching application written in C. It is kind of a main loop that for each value calls, for increasing values of "i", a function that performs some calculations. I read about...

View Article
Browsing all 14 articles
Browse latest View live




Latest Images