Question

I'm working on a project where we have to create a number of threads(actual number will be inputted in by testers (TA's)). I'm having trouble not only with the programming but also with the design, I can't wrap my head around all of the threads that will be invoked and where I might cause errors. The project is due soon so I don't want to waste time on this if it'll actually set me back, but I was wondering if I should write the program like only one thread will be running and everything should be sequential and then later go back and try to add the thread safety parts of the code? Would that take twice the original amount of time?

Project Description: Note:I'm going to be as vague as possible so I don't violate any honor codes, sorry :(

your program should accept n number of objectA threads, m number of objectB threads, and r number of objectC

objectB threads interact with code in objectA. objectA threads interact with code in objectB and objectC objectB and objectC don't directly interact, but do so indirectly through objectA -ex: objectB needs something from objectA. objectA gets the result for that something by calling objectC

my confusion stems mostly from the fact that all of this interactions will be done by m+n threads and there are various restrictions throughout the descriptions, like objectB can request something from objectA, and objectA has to wait for objectC to finish that something before returning it to objectB. Also each objectA thread can only work on one instruction from objectB at a time, etc. etc.

I just want to know if I write the code so that there is only 1 objectA, 1 objectB and 1 object C, can I go back and easily modify it so that those 1's can be changed to m, n and r?

Sorry again, if my description is a little bit confusing.

Was it helpful?

Solution

I was wondering if I should write the program like only one thread will be running and everything should be sequential and then later go back and try to add the thread safety parts of the code?

I would get the program working with a minimum of threads first. Then I would re-write it to use multiple threads. You shouldn't under-estimate how much work this can take and you have to re-visit all you assumptions when you do.

Would that take twice the original amount of time?

At least twice as a long but it is more likely to work. If you try to do it all at once, it likely you will end up with a mess than won't work at all. If you are given marks for effort and it doesn't matter if you sometimes get thread safety bugs, then the all at once approach might give you the best marks. If you are developing professionally, it is far better to have some thing which work with one thread than something which has rare and unreproducible errors using multiple threads.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top