?
Solved

basic threading question

Posted on 2003-03-12
4
Medium Priority
?
238 Views
Last Modified: 2010-04-01
I am going to write a multithreaded program that will create two worker threads, which will be my mux and demux threads. they will have buffered input and output, respectively.

My questions:
Is it safe to use stl classes for my mux and demux threads?
If it is safe, should I use stl or would it be preferable to create them from scratch?
Are there any performance issues I should know about before I start?

I am not looking for anything to in depth. Just quick, short answers will be fine.
0
Comment
Question by:gandalf79
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 2

Author Comment

by:gandalf79
ID: 8122295
Oh, one more thing I forgot to mention. I am using MVC++7. The Thread will have access to MFC (But it is not required for this section).
0
 
LVL 46

Accepted Solution

by:
Kent Olsen earned 200 total points
ID: 8122501

STL should be fine for your application.  It's based on a thread-safe model that should be fine for most applications.


Don't re-invent the wheel.  The bottom line is getting your application running, not what parts go into it.  Take the "easy" and safe route now and if you still want to build your own thread class later you'll have more experience with threaded applications.  I suspect that you'll discover no need to build your own wrapper classes.

I doubt that you can write your own thread classes (or entire thread model) that will be any faster.

Give STL a try.


Kdo
0
 
LVL 2

Author Comment

by:gandalf79
ID: 8122576
That is all I needed to know thanks for the quick responce.
0
 
LVL 5

Expert Comment

by:Kocil
ID: 8122596
STL is thread safe in the context of they don't use global variables. So if you use 2 separated STL objects in 2 separated threads, it should be safe.

However, STL does not lock automatically. So if you use 1 STL object that is shared between 2 threads, you have to explicitly lock the STL object. You may need semaphore for locking.





0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question