Log inRegister an accountBrowse CSDbHelp & documentationFacts & StatisticsThe forumsAvailable RSS-feeds on CSDbSupport CSDb Commodore 64 Scene Database
You are not logged in - nap
CSDb User Forums


Forums > C64 Coding > Some sort of multithreading.
2008-04-08 22:51
gregg
Account closed

Registered: Apr 2005
Posts: 56
Some sort of multithreading.

About a week ago the topic multithreading came up on #c-64. So today I gave it a try. However, there's something wrong with my code and I can't really figure out what it is.

A short description: I have a fixed number of threads running and a CIA IRQ deals with context switching in a round-robin fashion. Every IRQ I save all current state data (SP, status register, PC, A, X, Y) in a structure and fetch the state data for the next thread.

In this example the first thread increments the screen background color (fast), while the second thread changes the border background color (slow). However the wait in the second thread runs too fast every other time, and I have no idea why. It's probably something wrong with the context switch stuff, maybe some of you could take a look at it?

Sources are for ACME.

!to "threading.prg",cbm
!cpu 6510
;!source "mylib.a"
!macro basic_header .a, .b, .c, .d {
        *= $0801
        !byte <.eol,>.eol,0,0,$9e
        !text .a, .b, .c, .d
.eol:   !byte 0,0,0
}

num_threads = 2
thread_num = $fd		; current thread number

;--------------------------------------------------------------------------
+basic_header "2", "0", "6", "1"

*= $080d

init:	sei
		; set up context switch IRQ
		lda #$35
		sta $01

		lda #<context_switch
		ldx #>context_switch
		sta $fffe
		stx $ffff
		
		lda #0
		sta thread_num

		cli
		jmp thread1

;--------------------------------------------------------------------------
context_switch:
		pha
		txa
		pha
		tya
		pha
		lda $dc0d

		; save current thread
		lda thread_num
		; *8
		asl
		asl
		asl
		tay
		; save A,X,Y
		pla
		sta thread_data+6,y
		pla
		sta thread_data+5,y
		pla
		sta thread_data+4,y
		; save PSW
		pla
		sta thread_data+1,y
		; save PC
		pla
		sta thread_data+2,y
		pla
		sta thread_data+3,y
		; save SP
		tsx
		txa
		sta thread_data,y

		; next thread, wraparound
		ldy thread_num
		iny
		cpy #num_threads
		bne +
		ldy #0
+		sty thread_num

		; *8
		tya
		asl
		asl
		asl
		tay

		; restore thread data
		; stack pointer first
		lda thread_data,y
		tax
		txs
		; push PC, PSW for RTI
		lda thread_data+3,y
		pha
		lda thread_data+2,y
		pha
		lda thread_data+1,y
		pha
		; push registers
		lda thread_data+6,y
		pha
		lda thread_data+5,y
		pha
		lda thread_data+4,y
		pha

		pla
		tay
		pla
		tax
		pla
		rti
	
;--------------------------------------------------------------------------
thread1:
		inc $d021
		ldy #$02
		jsr wait2
		jmp thread1


thread2:
		inc $d020
		ldy #$80
		jsr wait2
		jmp thread2
		
wait2:
-		ldx #0
		dex
		bne *-1
		dey
		bne -
		rts

;--------------------------------------------------------------------------
thread_data:
	!fill 8, 0
	!byte $ff-$40, $22, <thread2, >thread2, 0,0,0,0

 
... 211 posts hidden. Click here to view all posts....
 
2008-04-17 15:26
Oswald

Registered: Apr 2002
Posts: 5026
so, and are you sure that Amiga OS's tasks which are like the threads of OS/2 can support threads ? can you cite any definition of multitasking which makes it a neccesity that multitasking = ability to support threads? :) You CANT. its your stupid definition.

also telling me that I am confused and I am wrong does not proove anything. try reasoning that will help :)

the meaning of heavyweight and lightweight cannot be seriously interpreted without the context of an OS. as I already told you whats a heavyweight task in AmigaOS is a lightweight thread in OS/2.

"You are also wrong because you misquote what I have been writing. What I hacve been writing is this:"

I have only quoted what you have written: there's no misquoting in it

"Multi-tasking = Multiple processes that can support multiple threads. A hierarchy."

and there's nothing in the same post of the above quote you are trying now to make up was beside this sentence, in other words: you are lying again.

"This also shows why you are wrong because the definition of hierarchy is wider than just your misquote."

if the quote is wrong then YOU are wrong, because it was written by YOURSELF and not by me. liar.

2008-04-17 15:34
Oswald

Registered: Apr 2002
Posts: 5026
Skate, you example were only correct if your example processes were interacting through resource allocators and graphics drivers with sprites. examples can be wrong just like real life.

"Proofs? :) "

or aguments, whatever.

sentences like "oswald is wrong, x is not y but z" is not arguable. and I dont want to be involved in discussions like:

- x is y
- no x is z
- no x is y
- no x is z

etc.
2008-04-17 15:38
Martin Piper

Registered: Nov 2007
Posts: 645
Oswald, the whole of your posts show why you are wrong because what you are writing contradicts the links you have been posting.
You said "try reasoning that will help". The point is many other posters have tried reasoning with you and what you do is still keep on repeating your same mistaken assumptions and posting the same links that disprove what you are writing.

It is very obvious that you are confused and you are wrong.
2008-04-17 15:38
Skate

Registered: Jul 2003
Posts: 491
@Oswald: This is my last post in this discussion. And I'm not writing anything against yours or anyone else's idea. I've already written what I know, what I think of. Now it's time for me to fuck off. Have fun...
2008-04-17 15:44
Martin Piper

Registered: Nov 2007
Posts: 645
Quote: @Oswald: This is my last post in this discussion. And I'm not writing anything against yours or anyone else's idea. I've already written what I know, what I think of. Now it's time for me to fuck off. Have fun...

Oswald is now using personal attacks because he knows his argument has failed and he knows he is wrong. He just doesn't want to admit it.
2008-04-17 15:52
chatGPZ

Registered: Dec 2001
Posts: 11145
atleast he isn't trolling (like me)
2008-04-17 15:57
Trash

Registered: Jan 2002
Posts: 122
Cant someone explain the difference between threads and processes, please?
2008-04-17 16:01
Martin Piper

Registered: Nov 2007
Posts: 645
I just checked the thread, those disagreeing with what Oswald writes are: Trident, Krill, Gregg, JackAsser, Skate and myself.
Those agreeing with Oswald are: *sound of crickets*
2008-04-17 16:03
Martin Piper

Registered: Nov 2007
Posts: 645
Quote: Cant someone explain the difference between threads and processes, please?

It is generally accepted that multiple threads can live inside one process.

In MS Windows terms, a process is what you get when you run an EXE. This process can have one or more threads running. Hence you see a hierarchy of processes owning their own threads.
2008-04-17 16:04
chatGPZ

Registered: Dec 2001
Posts: 11145
the difference can only be explained in the context of the execution environment. (to pull my example again, in the OS of the PSP, everything is a "process". a comparable thing with similar properties in the context of a unixish OS would only qualify as a thread)
Previous - 1 | ... | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 - Next
RefreshSubscribe to this thread:

You need to be logged in to post in the forum.

Search the forum:
Search   for   in  
All times are CET.
Search CSDb
Advanced
Users Online
Zartan/Unit 5
mutetus/Ald ^ Ons
Hok/Remember
Fred/Channel 4
JCH/Vibrants
Ax!s/Onslaught - TND
Guests online: 144
Top Demos
1 Next Level  (9.8)
2 13:37  (9.7)
3 Mojo  (9.7)
4 Coma Light 13  (9.7)
5 Edge of Disgrace  (9.6)
6 Comaland 100%  (9.6)
7 Uncensored  (9.6)
8 No Bounds  (9.6)
9 Wonderland XIV  (9.6)
10 Bromance  (9.5)
Top onefile Demos
1 Layers  (9.7)
2 It's More Fun to Com..  (9.6)
3 Cubic Dream  (9.6)
4 Party Elk 2  (9.6)
5 Copper Booze  (9.6)
6 TRSAC, Gabber & Pebe..  (9.5)
7 Rainbow Connection  (9.5)
8 Dawnfall V1.1  (9.5)
9 Quadrants  (9.5)
10 Daah, Those Acid Pil..  (9.5)
Top Groups
1 Oxyron  (9.3)
2 Booze Design  (9.3)
3 Censor Design  (9.3)
4 Crest  (9.3)
5 Performers  (9.3)
Top Organizers
1 Burglar  (9.9)
2 Sixx  (9.8)
3 hedning  (9.7)
4 Irata  (9.7)
5 MWS  (9.6)

Home - Disclaimer
Copyright © No Name 2001-2024
Page generated in: 0.049 sec.