Threads sharing code

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
stanko51
Member
Member
Posts: 32
Joined: Fri Mar 27, 2009 6:58 pm

Threads sharing code

Post by stanko51 »

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.
egos
Member
Member
Posts: 612
Joined: Fri Nov 16, 2007 1:59 pm

Re: Threads sharing code

Post by egos »

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.
stanko51
Member
Member
Posts: 32
Joined: Fri Mar 27, 2009 6:58 pm

Re: Threads sharing code

Post by stanko51 »

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 ^^
Hyperdrive
Member
Member
Posts: 93
Joined: Mon Nov 24, 2008 9:13 am

Re: Threads sharing code

Post by Hyperdrive »

stanko51 wrote:How to implement it, create new threads, handle switching between threads... ? Just some tips on where to start would be much appreciated ^^
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.

--TS
egos
Member
Member
Posts: 612
Joined: Fri Nov 16, 2007 1:59 pm

Re: Threads sharing code

Post by egos »

stanko51 wrote:How to implement it, create new threads, handle switching between threads... ? Just some tips on where to start would be much appreciated ^^
Make double-direction ring queue where will be placed all running (not waiting) threads. And realize thread context switching on timer interrupts.
If you have seen bad English in my words, tell me what's wrong, please.
jal
Member
Member
Posts: 1385
Joined: Wed Oct 31, 2007 9:09 am

Re: Threads sharing code

Post by jal »

stanko51 wrote:How to implement it, create new threads, handle switching between threads... ?
Check the wiki, perhaps?


JAL
Post Reply