Concurrent Programming:Should I write a sequential program first, then add thread safety?
- by evthim
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.