Click here to Skip to main content
16,012,061 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Unmanaged Threading Pin
led mike13-Jun-06 10:59
led mike13-Jun-06 10:59 
GeneralRe: Unmanaged Threading Pin
Jun Du13-Jun-06 12:25
Jun Du13-Jun-06 12:25 
GeneralRe: Unmanaged Threading Pin
Graham Bradshaw13-Jun-06 12:33
Graham Bradshaw13-Jun-06 12:33 
GeneralRe: Unmanaged Threading Pin
Joe Woodbury13-Jun-06 13:07
professionalJoe Woodbury13-Jun-06 13:07 
GeneralRe: Unmanaged Threading Pin
Arvind Bharti13-Jun-06 20:23
Arvind Bharti13-Jun-06 20:23 
GeneralRe: Unmanaged Threading Pin
Joe Woodbury13-Jun-06 21:19
professionalJoe Woodbury13-Jun-06 21:19 
GeneralRe: Unmanaged Threading Pin
Sarath C13-Jun-06 19:40
Sarath C13-Jun-06 19:40 
GeneralRe: Unmanaged Threading Pin
Jun Du14-Jun-06 4:15
Jun Du14-Jun-06 4:15 
Using CreateThread is not thread safe, not because CreateThread is not thread safe itself, but because using it in applications linked with a CRT (C/C++ Run-Time) library is not. Some notable items:

1) The applications built on VC++ 6, regardless of type, have been linked to one of the CRT libraries shiped with VC++:

Single-Threaded (default)
Multithreaded
Multithreaded DLL
Debug Single-Threaded
Debug Multithreaded
Debug Multithreaded DLL

You could avoid calling CRT functions in your module, but you have no control over who, where and when CRT is used in the application.

2) For multithreaded C/C++ to work properly, a data structure must be created and associated with each thread that uses CRT functions. CreateThread is an OS call, but _beginthreaded is a CRT call. If you call CreateThread, OS doesn't know:
- your application is written in C/C++,
- you are calling functions that aren't natively thread-safe
- it needs to allocate a CRT data block for the new thread
When you call _beginthreaded, CRT knows and handles all these in a proper manner. Then, CRT calls CreateThread inside _beginthreaded to actually create the thread you wanted.

Jeffery Richter's classic text "Programming Applications for Microsoft Windows" (4th Ed.) Chapter 6 has explained this in more detail.



- It's easier to make than to correct a mistake.
QuestionCButton, BS_BITMAP, LoadImage Issue and Question. Pin
Maximilien13-Jun-06 10:38
Maximilien13-Jun-06 10:38 
QuestionRe: CButton, BS_BITMAP, LoadImage Issue and Question. Pin
David Crow13-Jun-06 10:43
David Crow13-Jun-06 10:43 
QuestionWriteConsole() problem Pin
CoffeeAddict1913-Jun-06 10:00
CoffeeAddict1913-Jun-06 10:00 
QuestionRe: WriteConsole() problem Pin
David Crow13-Jun-06 10:06
David Crow13-Jun-06 10:06 
AnswerRe: WriteConsole() problem Pin
CoffeeAddict1914-Jun-06 5:45
CoffeeAddict1914-Jun-06 5:45 
QuestionRe: WriteConsole() problem Pin
David Crow14-Jun-06 5:52
David Crow14-Jun-06 5:52 
QuestionNewbie needs help generating html files from user input via windows gui [modified] Pin
dstrain13-Jun-06 9:35
dstrain13-Jun-06 9:35 
AnswerRe: Newbie needs help generating html files from user input via windows gui Pin
Mark F.14-Jun-06 4:54
Mark F.14-Jun-06 4:54 
Questionlaunching notepad.exe and reading the current date/time Pin
Mahhouraaaaaa13-Jun-06 8:30
Mahhouraaaaaa13-Jun-06 8:30 
AnswerRe: launching notepad.exe and reading the current date/time [modified] Pin
Mark F.13-Jun-06 8:59
Mark F.13-Jun-06 8:59 
AnswerRe: launching notepad.exe and reading the current date/time Pin
Hamid_RT13-Jun-06 19:07
Hamid_RT13-Jun-06 19:07 
AnswerRe: launching notepad.exe and reading the current date/time Pin
Laxman Auti13-Jun-06 19:30
Laxman Auti13-Jun-06 19:30 
QuestionC++ Forum Pin
knoxplusplus13-Jun-06 8:24
knoxplusplus13-Jun-06 8:24 
QuestionHello a problem with Cstring :) Pin
Mahhouraaaaaa13-Jun-06 6:16
Mahhouraaaaaa13-Jun-06 6:16 
AnswerRe: Hello a problem with Cstring :) Pin
Neil Van Eps13-Jun-06 6:17
Neil Van Eps13-Jun-06 6:17 
GeneralRe: Hello a problem with Cstring :) Pin
Mahhouraaaaaa13-Jun-06 6:23
Mahhouraaaaaa13-Jun-06 6:23 
JokeRe: Hello a problem with Cstring :) Pin
Laxman Auti13-Jun-06 19:32
Laxman Auti13-Jun-06 19:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.