Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 02-03-2005, 09:13 PM   #1 (permalink)
toast28
Registered User
 
Join Date: Sep 2004
Posts: 21
toast28 is on a distinguished road
Threads and fstream

Can someone (read: Valmont,lol) explain to me how to share an open fstream between 2 threads in a multithreaded program? I tried declaring it as a global outfile, but when it gets to the function in another file it says it doesn't recognize the variable outfile. My teacher said something about declaring it a pointer to a fstream then dereferencing it in the function, but I haven't had any luck doing that yet.

The program is fundementally simple, output greeting message, start thread, get 2 random nums, wait for child, output both nums and child threads id. The thread runs function void* getnumbers (void* data), which generates random nums, outputs this threads id and numbers to file, then returns numbers.

I hope you can explain this to me.
toast28 is offline   Reply With Quote
Old 02-03-2005, 10:04 PM   #2 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,544
Valmont is on a distinguished road
Threads are not supported by the standard, so I don't support them either.
However, your hint is that you can declare the stream static. In that case the stream will be shared by all threads.
You can call the member function that is shared between threads.
Are you using posix as well?
__________________
Valmont is offline   Reply With Quote
Old 02-03-2005, 10:52 PM   #3 (permalink)
toast28
Registered User
 
Join Date: Sep 2004
Posts: 21
toast28 is on a distinguished road
I am using Posix theads, its on a FreeBDS system, if that makes a differnce.

I'll try the static idea, do I still need to declare it as a pointer then?
toast28 is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -8. The time now is 06:30 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting