Hello,
How can you implement 2 threads that will share executable code?
For example I load a first thread with a "main" and all different functions. Then I want to load a second thread with only the "main fonction" that will be able to use function defined in the first thread.
I'd like to do that using paging althought i realise it'd be easier with segmentation.
This would be some kind of "duplicating thread", but I'm not really sure where to start to implement it.
Thank you for your help.
Threads sharing code
Re: Threads sharing code
Threads of one process run in same address space therefore they share code by default. Each thread must have its own stack.
If you have seen bad English in my words, tell me what's wrong, please.
Re: Threads sharing code
Ok egos, thank you,
How to implement it, create new threads, handle switching between threads... ? Just some tips on where to start would be much appreciated ^^
How to implement it, create new threads, handle switching between threads... ? Just some tips on where to start would be much appreciated ^^
-
- Member
- Posts: 93
- Joined: Mon Nov 24, 2008 9:13 am
Re: Threads sharing code
Basically it comes down to process switching. If you can do that, you can switch threads too. You can optimize it a bit: If you switch from a thread of process P to a thread of the same process P, you don't need to switch address spaces (because all threads of the same process use the same address space). That's mainly the idea behind having threads and not just plain processes.stanko51 wrote:How to implement it, create new threads, handle switching between threads... ? Just some tips on where to start would be much appreciated ^^
--TS
Re: Threads sharing code
Make double-direction ring queue where will be placed all running (not waiting) threads. And realize thread context switching on timer interrupts.stanko51 wrote:How to implement it, create new threads, handle switching between threads... ? Just some tips on where to start would be much appreciated ^^
If you have seen bad English in my words, tell me what's wrong, please.
Re: Threads sharing code
Check the wiki, perhaps?stanko51 wrote:How to implement it, create new threads, handle switching between threads... ?
JAL