0

Is there any simple example you know? (with using getcontext, setcontext, makecontext)

I found some examples but they are a bit high level.

I just need to create threads and yield between them for now.

funky-nd
  • 637
  • 1
  • 9
  • 25

1 Answers1

1

You didn't do any research. This is a pretty basic question.

http://softpixel.com/~cwright/programming/threads/threads.c.php

How to "multithread" C code

Question on Getcontext function

Community
  • 1
  • 1
Nova Ardent
  • 161
  • 1
  • 16
  • 1
    but these use pthread library :( – funky-nd Mar 10 '17 at 03:33
  • You're not using a posix system then i take it? – Nova Ardent Mar 10 '17 at 03:34
  • http://stackoverflow.com/questions/13283294/how-to-make-thread-in-c-without-using-posix-library-pthread-h – Nova Ardent Mar 10 '17 at 03:35
  • http://www.unix.com/man-page/All/3/getcontext/ – Nova Ardent Mar 10 '17 at 03:36
  • http://stackoverflow.com/questions/35047816/ucontext-h-and-uc-link-not-returning-from-main-thread – Nova Ardent Mar 10 '17 at 03:37
  • yes I saw them but could not manage to write thread_create and thread_yield methods with using functions getcontext setcontext :( – funky-nd Mar 10 '17 at 03:38
  • Jo s, last one was what I was looking for. However, it will be still hard to make a library with only these information. I am working on it, anyways. – funky-nd Mar 10 '17 at 03:40
  • I recommend getting more comfortable with manual pages down the road. What they mean with each of the pieces of information, and their descriptions. It will help in the long run. Hopefully i was helpful! – Nova Ardent Mar 10 '17 at 03:41
  • i am combining pieces that I learn. For example, here there is a struct TCB: http://stackoverflow.com/questions/23073007/segmentation-fault-using-getcontext-in-thread-library. I will need this, too – funky-nd Mar 10 '17 at 03:42
  • Multi threading isn't an easy topic persay. There is a lot to keep in mind when doing it. It's much easier in a posix system, but unfortunately it doesn't seem like you have those resources available. – Nova Ardent Mar 10 '17 at 03:44