Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


basic threading question

Posted on 2003-03-12
Medium Priority
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.
Question by:gandalf79
  • 2

Author Comment

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).
LVL 46

Accepted Solution

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.


Author Comment

ID: 8122576
That is all I needed to know thanks for the quick responce.

Expert Comment

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.


Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
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.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

580 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