Mailing List archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[vdr] Re: thread proof/reentrance



On Saturday 04 December 2004 15:36, Rainer Zocholl wrote:
> While digging in the code:
>
> msi:~/video/VDR# grep strtok *.c *.h | grep -v strok_r
> channels.c:           while ((q = strtok(p, ",")) != NULL) {
> channels.c:              while ((q = strtok(p, ",")) != NULL) {
> channels.c:              while ((q = strtok(p, ",")) != NULL) {
> keys.c:  while ((p = strtok(s, " \t")) != NULL) {
> svdrp.c:     FileName = strtok(p, delim);
> svdrp.c:     if ((p = strtok(NULL, delim)) != NULL) {
> svdrp.c:     if ((p = strtok(NULL, delim)) != NULL) {
> svdrp.c:     if ((p = strtok(NULL, delim)) != NULL) {
> svdrp.c:        if ((p = strtok(NULL, delim)) != NULL) {
> svdrp.c:     if ((p = strtok(NULL, delim)) != NULL) {
> svdrp.c:        char *p = strtok(buf, delim);
> svdrp.c:                 if ((p = strtok(NULL, delim)) != NULL) {
> svdrp.c:              p = strtok(NULL, delim);
>
>
>
> is strtok really thread proof?

No, it is not. You have to use strtok_r.

There are several clib functions that are not thread safe, including
strerror (as funny as it may sound from a programmers point of view).

> Why are no side effects to be expected?
> How is that guarantied?

The code will simply be broken if you use those functions.

However, as long as this happens at startup where no other thread
is running you should be safe. But using strtok_r everywhere does
not hurt and makes code more safe for future changes.

All functions that have a thread safe implementation (and some
more unfortunately):  apropos _r|egrep '^[a-z_]*_r '

Kind regards,
Stefan




Home | Main Index | Thread Index