LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-01-2006, 02:35 PM   #16
aceman817
LQ Newbie
 
Registered: Apr 2001
Distribution: Ubuntu 5.10
Posts: 24

Original Poster
Rep: Reputation: 15

Alright. That part was simple enough. I guess the function1 helps to initialize our variable.
 
Old 02-01-2006, 03:33 PM   #17
aceman817
LQ Newbie
 
Registered: Apr 2001
Distribution: Ubuntu 5.10
Posts: 24

Original Poster
Rep: Reputation: 15
I have to go to class in about 45 minutes or so and won't return till about 9:15PM EST. I'll try and check this forum if I'm able to. Thanks again for your assistance. I'm hoping that with your help, I'll be able to learn the solution to the problem and submit it by the 11PM EST deadline tonight.
 
Old 02-01-2006, 04:11 PM   #18
rstewart
Member
 
Registered: Feb 2005
Location: Sunnyvale, CA
Distribution: Ubuntu
Posts: 205

Rep: Reputation: 38
I'm based in PST and am currently helping you from work. I will be leaving in a few hours and won't be available again until tomorrow, depending on how much more assistance you need it is probably not feasible that you will make tonight's deadline.

Where we need to go from here is for you to look at how to code the reader thread function and the writer thread function. We also need to discuss locking mechanisms such as semaphores. Then you will need to add in the semaphore parts and write a main to launch everything. Then will come the debugging part.

Once all of these steps have been completed, you will have a program that will still behave in a serial manner. However you can use that code as a baseline to implement double buffering which should then deserialize the program's execution and give you true parallel threads. I wanted to start small and build up a foundation for you to use in future projects.

Things for you to look at are:

1) File I/O (opens, closes, reads, and writes)
2) pthread thread creation
3) pthread mutex semaphores
4) pthread thread termination and synchronization
 
Old 02-01-2006, 04:17 PM   #19
aceman817
LQ Newbie
 
Registered: Apr 2001
Distribution: Ubuntu 5.10
Posts: 24

Original Poster
Rep: Reputation: 15
It seems like there is still alot of things left to do! I have to submit something by the deadline as late work is not accepted. I'll look over those things you mentioned when I get home and hopefully I'll be able to arrive at something.
 
Old 02-01-2006, 04:48 PM   #20
rstewart
Member
 
Registered: Feb 2005
Location: Sunnyvale, CA
Distribution: Ubuntu
Posts: 205

Rep: Reputation: 38
The best of luck to you! I am sure you will be able to come up with something! It really is a fairly easy and simple task.

Code:
You will have a main task that does the following:

Processes command line arguments (gets the name of the input and output files)
Create and initialize a mutex semaphore (number 1) to the locked state
Create and initialize a mutex semaphore (number 2) to the unlocked state
Spawn a reader task
Call a writer function (this thread becomes the writer task)
Upon return, wait for reader task to terminate
Terminate program

You will have a reader task that does the following:

Open the input file
Enter into a data reading loop
  Take semaphore number 2
  Read in data into a global buffer
  If ( EOF )
    Close input file
    Set number of bytes read global variable to -1
    Give (free up) semaphore 1
    Terminate thread
  Assign number of bytes read global with the number actually read
  Give (free up) semaphore number 1
  Go to beginning of loop

You will have a writer function that does the following:

Open the output file
Enter into a data writing loop
  Take semaphore number 1
  If ( number of bytes read global variable == -1 )
    Close output file
    Return from function
  Write data in buffer to output file
  Give (free up) semaphore number 2
  Go to beginning of loop
That in a nutshell is what is needed to create the simple serialized version of the program you are trying to code. I hope that this helps you. Please feel free to ask questions.
 
Old 02-01-2006, 04:59 PM   #21
aceman817
LQ Newbie
 
Registered: Apr 2001
Distribution: Ubuntu 5.10
Posts: 24

Original Poster
Rep: Reputation: 15
I'm writing just before my class now and that seems awfully long for a "simple" program. There has to be some kind of examples available out there that demonstrates this.
 
Old 02-01-2006, 05:26 PM   #22
rstewart
Member
 
Registered: Feb 2005
Location: Sunnyvale, CA
Distribution: Ubuntu
Posts: 205

Rep: Reputation: 38
Not really. It really is a very simple and easy program. The problems that you will run in to when executing a multi-tasking program are ones such as data synchronization issues, and communicating between linked threads.

Remember, you have a CPU with a thread or threads that can be stopped or started at any given point. There is no guarantee that any programmatic execution order is maintained unless you manually take steps to make sure things go correctly.

I think that what the purpose of this assignment was was to have you come to an understanding that once you deserialize events in an OS, a randomness factor is introduced that must be handled or the results will be chaos. We just barely scratched the surface of "real-time" programming where things like task priorities, interrupt latency, deadlock, and priority inversion come into play.

The basic technique to follow is to lock critical sections, and if the lock was granted, modify what needs to be modified, and release the lock. If the lock is not granted, then wait until it is granted because someone else is doing something at the moment and you could clobber what they are doing if you do your modifications at the same time or vice versa.

Have fun!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
About POSIX threads Ephracis Programming 1 12-03-2004 06:33 AM
fully statically linked posix thread program on PPC mmiglia Linux - Software 0 09-22-2004 07:06 AM
Posix arunshivanandan General 1 05-19-2003 08:07 AM
POSIX thread Ivan Lee Programming 2 03-28-2003 03:54 AM
Posix? justiceisblind Linux - Newbie 2 03-11-2002 08:04 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:17 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration