View Full Version : C threading
12-27-2011, 03:47 AM
Because the propeller was the first thing I ever programmed I've gotten very accustomed to doing multiple tasks at the same time and because of that reason I've shy ed away from the other one step at a time processors. I was wondering if someone could explain to me how to take the concept of multitasking of the propeller to my computer. I've searched google for some solution but it just confuses me. Currently I'm coding in C using Code Blocks and MinGW as my compiler.
12-27-2011, 04:28 AM
The C language runtime doesn't have threads built in like Java or C#. Instead programs call the underlying OS thread library, either pthreads on Unix like OS or Win32 threads on Windows. So a Google search should turn up some sample code your environment.
The thread paradigm is similar to the propeller's cogs, so you should get the hang of it quickly.
12-27-2011, 05:53 AM
Of course, that still implies you won't be able to use threads on a Propeller. Did you want both threads and cogs?
I doubt it would be worthwhile.
It may be possible on a Propeller, but it would all be rather limited in terms of code and space. One would have to create something like an interrupt in code.
12-27-2011, 08:20 AM
It implies no such thing.
In C you can run run multiple codes in multiple COGs just as you can in Spin. Catalina supports the pthreads API as does propgcc I believe. In addition with ProtoThreads or my smaller faster "Heater Threads" you can write multiple tasks that will run in a single COG.
12-27-2011, 04:55 PM
Sorry about the confusion, I'm not trying to thread on the Propeller but the aspect that that is possible is intriguing. I'm instead trying to understand how to thread on my computer as It would be helpful for my current project.
12-27-2011, 05:24 PM
Thanks, I learned something I didn't understand about Catalina.
12-27-2011, 06:05 PM
On your PC I'm sure there is a threading API for C under Windows but I'm no Windows programmer. Under Linux I would go straight to the pthreads (POSIX Threads) library functions.
However I like all my code to be cross platform so I would use a toolkit that provides my code with threads on many platforms. My current favorite at the moment is the Qt tool kit. It's for C++ but you could build non-gui console apps with the minimum amount of C++ "object orientedness" used to get the threads running.