Shop OBEX P1 Docs P2 Docs Learn Events
C threading — Parallax Forums

C threading

ThricThric Posts: 109
edited 2011-12-27 10:05 in General Discussion
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.
Thanks

Comments

  • Martin_HMartin_H Posts: 4,051
    edited 2011-12-26 20:28
    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.
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2011-12-26 21:53
    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.
  • Heater.Heater. Posts: 21,230
    edited 2011-12-27 00:20
    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.
  • ThricThric Posts: 109
    edited 2011-12-27 08:55
    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.
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2011-12-27 09:24
    Thanks, I learned something I didn't understand about Catalina.
  • Heater.Heater. Posts: 21,230
    edited 2011-12-27 10:05
    Thric,

    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.
Sign In or Register to comment.