Click here to Skip to main content
11,716,285 members (90,426 online)

C / C++ / MFC

 
QuestionHow can i create a project that it has the same name with an existing project Pin
November 201325-Mar-13 5:33
memberNovember 201325-Mar-13 5:33 
QuestionRe: How can i create a project that it has the same name with an existing project Pin
DavidCrow25-Mar-13 6:17
memberDavidCrow25-Mar-13 6:17 
AnswerRe: How can i create a project that it has the same name with an existing project Pin
November 201326-Mar-13 2:56
memberNovember 201326-Mar-13 2:56 
AnswerRe: How can i create a project that it has the same name with an existing project Pin
Richard MacCutchan25-Mar-13 7:32
mvpRichard MacCutchan25-Mar-13 7:32 
GeneralRe: How can i create a project that it has the same name with an existing project Pin
November 201326-Mar-13 4:03
memberNovember 201326-Mar-13 4:03 
QuestionRe: How can i create a project that it has the same name with an existing project Pin
DavidCrow26-Mar-13 4:13
memberDavidCrow26-Mar-13 4:13 
AnswerRe: How can i create a project that it has the same name with an existing project Pin
November 201326-Mar-13 4:18
memberNovember 201326-Mar-13 4:18 
AnswerRe: How can i create a project that it has the same name with an existing project Pin
November 201326-Mar-13 20:13
memberNovember 201326-Mar-13 20:13 
GeneralRe: How can i create a project that it has the same name with an existing project Pin
Richard MacCutchan26-Mar-13 6:39
mvpRichard MacCutchan26-Mar-13 6:39 
GeneralRe: How can i create a project that it has the same name with an existing project Pin
November 201326-Mar-13 20:11
memberNovember 201326-Mar-13 20:11 
GeneralDialog or “dynamic” Menu? Pin
Vaclav_Sal23-Mar-13 4:16
memberVaclav_Sal23-Mar-13 4:16 
GeneralRe: Dialog or “dynamic” Menu? Pin
Richard MacCutchan23-Mar-13 6:08
mvpRichard MacCutchan23-Mar-13 6:08 
GeneralRe: Dialog or “dynamic” Menu? Pin
pasztorpisti24-Mar-13 4:53
memberpasztorpisti24-Mar-13 4:53 
QuestionProblem with flockfile and funlockfile Pin
noislude23-Mar-13 4:09
membernoislude23-Mar-13 4:09 
Hi people. I've been reading Programming with POSIX Threads (I've been learning pthreads by myself) and I always get some errors when I attempt to use flockfile and funlockfile and I don't know how to get rid of these errors. Can you help me? thanks.

/*
 * putchar.c
 *
 * Demonstrate use of stdio file locking to generate an "atomic"
 * sequence of character writes (using putchar). If run with an
 * argument of "1", or no argument, the program uses a sequence
 * of putchar_unlocked calls within flockfile/funlockfile to
 * ensure that one threads writes cannot be interleaved with
 * another's.
 *
 * With an argument of "0", the program uses putchar, without
 * file locks, to show that the writes may be interleaved.
 *
 * The putchar[_unlocked] loop is punctuated with sleep(1) calls
 * to ensure that the desired behavior is demonstrated. Without
 * some delay, even on a multiprocessor the program may often
 * fail to display the interleaved output in this simplified
 * case.
 *
 * With file locking, you can expect to see the following output:
 *
 *      thread 1
 *      thread 2
 *      thread 3
 *
 * While without file locking, you can expect to see something
 * much less predictable, but probably resembling this:
 *
 *      ttthhhiiisss   iiisss   ttthhhrrreeeaaaddd   123
 *
 */
#include <pthread.h>
#include "errors.h"
 
/*
 * This function writes a string (the function's arg) to stdout,
 * by locking the file stream and using putchar_unlocked to
 * write each character individually.
 */
void *lock_routine (void *arg)
{
    char *pointer;
 
    flockfile (stdout);
    for (pointer = arg; *pointer != '\0'; pointer++) {
        putchar_unlocked (*pointer);
        sleep (1);
    }
    funlockfile (stdout);
    return NULL;
}
 
/*
 * This function writes a string (the function's arg) to stdout,
 * by using putchar to write each character individually.
 * Although the internal locking of putchar prevents file stream
 * corruption, the writes of various threads may be interleaved.
 */
void *unlock_routine (void *arg)
{
    char *pointer;
 
    for (pointer = arg; *pointer != '\0'; pointer++) {
        putchar (*pointer);
        sleep (1);
    }
    return NULL;
}
 
int main (int argc, char *argv[])
{
    pthread_t thread1, thread2, thread3;
    int flock_flag = 1;
    void *(*thread_func)(void *);
    int status;
 
    if (argc > 1)
        flock_flag = atoi (argv[1]);
    if (flock_flag)
        thread_func = lock_routine;
    else
        thread_func = unlock_routine;
    status = pthread_create (
        &thread1, NULL, thread_func, "this is thread 1\n");
    if (status != 0)
        err_abort (status, "Create thread");
    status = pthread_create (
        &thread2, NULL, thread_func, "this is thread 2\n");
    if (status != 0)
        err_abort (status, "Create thread");
    status = pthread_create (
        &thread3, NULL, thread_func, "this is thread 3\n");
    if (status != 0)
        err_abort (status, "Create thread");
    pthread_exit (NULL);
}

after running valgrind --tool=helgrind --tool=drd

=5790== Thread 3:
==5790== Conflicting load by thread 3 at 0x053fb7e8 size 8
==5790==    at 0x4E4D063: flockfile (in /lib64/libpthread-2.15.so)
==5790==    by 0x4009B6: lock_routine (putchar.c:20)
==5790==    by 0x4C2D231: ??? (in /usr/lib64/valgrind/vgpreload_drd-amd64-linux.so)
==5790==    by 0x4E45E0D: start_thread (pthread_create.c:305)
==5790== Allocation context: BSS section of /lib64/libc-2.15.so
==5790== Other segment start (thread 2)
==5790==    at 0x513E291: clone (clone.S:84)
==5790== Other segment end (thread 2)
==5790==    at 0x510FCAD: ??? (syscall-template.S:82)
==5790==    by 0x510FB50: sleep (sleep.c:138)
==5790==    by 0x4009DB: lock_routine (putchar.c:24)
==5790==    by 0x4C2D231: ??? (in /usr/lib64/valgrind/vgpreload_drd-amd64-linux.so)
==5790==    by 0x4E45E0D: start_thread (pthread_create.c:305)
==5790==
Create thread 3 "putchar.c": 64 Success
t==5790==
==5790== For counts of detected and suppressed errors, rerun with: -v
==5790== ERROR SUMMARY: 2 errors from 1 contexts (suppressed: 38 from 38)

Question(ask) need help how to divide a file into some file Pin
moonstalker23-Mar-13 3:49
membermoonstalker23-Mar-13 3:49 
AnswerRe: (ask) need help how to divide a file into some file Pin
dusty_dex23-Mar-13 4:36
memberdusty_dex23-Mar-13 4:36 
GeneralRe: (ask) need help how to divide a file into some file Pin
moonstalker23-Mar-13 8:53
membermoonstalker23-Mar-13 8:53 
AnswerRe: (ask) need help how to divide a file into some file Pin
ramrooney26-Mar-13 7:39
memberramrooney26-Mar-13 7:39 
SuggestionRe: (ask) need help how to divide a file into some file Pin
Max_Power_Up27-Mar-13 0:48
memberMax_Power_Up27-Mar-13 0:48 
QuestionHelp needed to print the value nth number raised to the power n. Pin
Rajdeep_22-Mar-13 21:46
memberRajdeep_22-Mar-13 21:46 
AnswerRe: Help needed to print the value nth number raised to the power n. Pin
Richard MacCutchan22-Mar-13 23:47
mvpRichard MacCutchan22-Mar-13 23:47 
GeneralRe: Help needed to print the value nth number raised to the power n. Pin
Rajdeep_23-Mar-13 0:08
memberRajdeep_23-Mar-13 0:08 
AnswerRe: Help needed to print the value nth number raised to the power n. Pin
V.J.NAGA VARA PRASAD23-Mar-13 4:36
memberV.J.NAGA VARA PRASAD23-Mar-13 4:36 
AnswerRe: Help needed to print the value nth number raised to the power n. Pin
Vaclav_Sal23-Mar-13 4:52
memberVaclav_Sal23-Mar-13 4:52 
GeneralRe: Help needed to print the value nth number raised to the power n. Pin
Richard MacCutchan23-Mar-13 6:00
mvpRichard MacCutchan23-Mar-13 6:00 
SuggestionRe: Help needed to print the value nth number raised to the power n. Pin
DavidCrow23-Mar-13 16:05
memberDavidCrow23-Mar-13 16:05 
QuestionDirectX SDK – which version? Pin
Vaclav_Sal22-Mar-13 8:38
memberVaclav_Sal22-Mar-13 8:38 
AnswerRe: DirectX SDK – which version? Pin
dusty_dex22-Mar-13 8:45
memberdusty_dex22-Mar-13 8:45 
QuestionUse InternetSetOption() to change proxy Pin
Oren_Davod21-Mar-13 23:03
memberOren_Davod21-Mar-13 23:03 
AnswerRe: Use InternetSetOption() to change proxy Pin
Richard MacCutchan21-Mar-13 23:38
mvpRichard MacCutchan21-Mar-13 23:38 
Generalc++ queue OUTPUT ? Pin
kr kumar21-Mar-13 9:33
memberkr kumar21-Mar-13 9:33 
GeneralRe: c++ queue OUTPUT ? Pin
jeron121-Mar-13 10:18
memberjeron121-Mar-13 10:18 
QuestionRe: c++ queue OUTPUT ? Pin
DavidCrow21-Mar-13 17:08
memberDavidCrow21-Mar-13 17:08 
QuestionChoosing which information that Windows Vista's folder contents displayer is to display Pin
Anthony Appleyard21-Mar-13 3:41
memberAnthony Appleyard21-Mar-13 3:41 
AnswerRe: Choosing which information that Windows Vista's folder contents displayer is to display Pin
DavidCrow21-Mar-13 4:44
memberDavidCrow21-Mar-13 4:44 
GeneralRe: Choosing which information that Windows Vista's folder contents displayer is to display Pin
Anthony Appleyard21-Mar-13 5:16
memberAnthony Appleyard21-Mar-13 5:16 
GeneralRe: Choosing which information that Windows Vista's folder contents displayer is to display Pin
DavidCrow21-Mar-13 5:26
memberDavidCrow21-Mar-13 5:26 
GeneralRe: Choosing which information that Windows Vista's folder contents displayer is to display Pin
Anthony Appleyard21-Mar-13 6:07
memberAnthony Appleyard21-Mar-13 6:07 
GeneralRe: Choosing which information that Windows Vista's folder contents displayer is to display Pin
DavidCrow21-Mar-13 6:14
memberDavidCrow21-Mar-13 6:14 
GeneralRe: Choosing which information that Windows Vista's folder contents displayer is to display Pin
Anthony Appleyard21-Mar-13 7:49
memberAnthony Appleyard21-Mar-13 7:49 
GeneralRe: Choosing which information that Windows Vista's folder contents displayer is to display Pin
DavidCrow21-Mar-13 7:58
memberDavidCrow21-Mar-13 7:58 
GeneralRe: Choosing which information that Windows Vista's folder contents displayer is to display Pin
Anthony Appleyard21-Mar-13 11:05
memberAnthony Appleyard21-Mar-13 11:05 
GeneralRe: Choosing which information that Windows Vista's folder contents displayer is to display Pin
DavidCrow21-Mar-13 17:01
memberDavidCrow21-Mar-13 17:01 
QuestionRAII Theory Pin
Richard Andrew x6421-Mar-13 1:52
memberRichard Andrew x6421-Mar-13 1:52 
AnswerRe: RAII Theory Pin
Stephen Hewitt21-Mar-13 6:41
memberStephen Hewitt21-Mar-13 6:41 
AnswerRe: RAII Theory Pin
pasztorpisti22-Mar-13 3:41
memberpasztorpisti22-Mar-13 3:41 
GeneralRe: RAII Theory Pin
Stephen Hewitt22-Mar-13 21:17
memberStephen Hewitt22-Mar-13 21:17 
GeneralRe: RAII Theory Pin
pasztorpisti23-Mar-13 1:06
memberpasztorpisti23-Mar-13 1:06 
GeneralRe: RAII Theory Pin
Stephen Hewitt24-Mar-13 8:27
memberStephen Hewitt24-Mar-13 8:27 
GeneralRe: RAII Theory Pin
pasztorpisti24-Mar-13 8:44
memberpasztorpisti24-Mar-13 8:44 

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

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


Advertise | Privacy | Mobile
Web03 | 2.8.150901.1 | Last Updated 3 Sep 2015
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid