Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Drazgal

Quick Multithreading question

This topic is 5356 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Is there any way (or event) in win32 to call a function whenever a thread starts its share of the processing time? So no matter what the thread was doign it would run a different fuction before using the rest of its time share on the work it was doing?

Share this post


Link to post
Share on other sites
Advertisement
your question is a bit unclear. do you want the thread to run a certain function when it starts, or do you want the thread to run a certain function every time the processing context switches to the thread. are you trying to see how many times the processor switches between threads. if you are, let me suggest AGAINST trying something like this: 1) i'm pretty sure it's not possible 2) thread context switches happen way more often than you probably thing. it could, for instance, switch context every single time you finished that special function so you'd never actually get to run any of that thread's specific logic.

anyway, please clarify your question

-me

[edited by - Palidine on April 14, 2004 12:49:25 PM]

Share this post


Link to post
Share on other sites
Im trying to emulate a memory manager in software for a uni prject (with none of the special hardware), some of the algorithms require the OS to do things to the process as it is switched back onto the processor. I think you are right in thats not possible (well outside of writting an OS ). I can fake most of it though, just was wondering if I could take it one step too far

Share this post


Link to post
Share on other sites
You could write your own scheduler which runs multiple threads inside a single OS thread. This has been done before, but it challenging. It requires use of setjmp() and longjmp().

That would give you ultimate control; some modelling tools do this to get better control over the scheduler. You will have to have your different tasks explicitly call yield when they want to give up CPU and be switched. Or something.

I don''t see how you can run some code on context switches by the OS (in any OS); because the program counter could be anywhere in any function (including C library routines, or inside the routine that was already running following a previous context switch), even if you could, I don''t see how it could work without crashing.

Mark

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!